How do I query for several values that match the criteria in a field?
Is this the query? SELECT * FROM table where cateid=2 or cateid=4 or cateid=8 there is no other way:
I now get a character cateid= "2,4,8," what is the easiest way to take out the values that meet the criteria, Cateid the value of the length is not fixed, it may be cateid= "2,4,8,23,44," may also be cateid= "2,"
Thank you........
------Solution--------------------
SELECT * FROM table where Cateid in (2,4,8)
------Solution--------------------
Query with in condition, but the last face of the condition (, comma) is removed
------Solution--------------------
SQL Code
SELECT * FROM table where cate_id in (2,4,8)
------Solution--------------------
Or efficiency should be higher, it is easier to write in.
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);