How can I query the values that match the conditions in a field? Is there any other way to query select * fromtablewherecateid2orcateid4orcateid8 .. I now get the cateid & quot; 2, 4, 8, & quot; character. Is there any easy way to obtain the qualified value? the length of the cateid value is not fixed, it is possible that cate needs to filter several values that meet the conditions in a field. how can this problem be queried?
Is this the case? select * from table where cateid = 2 or cateid = 4 or cateid = 8 is there any other method ..
I now get the cateid = "2, 4, 8,". Is there any simple way to obtain the value that meets the condition? the length of the value of cateid is not fixed, it may be cateid = "2, 4, 8, 23, 44," or cateid = "2 ,"
Thank you ........
------ Solution --------------------
Select * from table where cateid in (2, 4, 8)
------ Solution --------------------
Use the in condition to query, but remove the (, comma) at the end of the condition
------ Solution --------------------
SQL code
Select * from table where cate_id in (2, 4, 8)
------ Solution --------------------
Or is it more efficient to use or? it is easier to use in writing.
PHP code
$a=explode(',',"2,4,8,23,44,");$w = array();foreach($a as $s){ if(intval($s)) $w[]='cate_id='.intval($s);}if(count($w)) echo "select * from table where ".implode(' or ',$w);