是这样查询吗 select * from table where cateid=2 or cateid=4 or cateid=8 有没有其它方法..我现在得到一个字符中cateid="2,4,8," 有什么简便的方法把符合条件的值给取出来呢,cateid的值长度不固定,有可能是cateid="2,4,8,23,44," 也有可能是cateid="2," 谢谢........
select * from table where cate_id in (2,4,8)把你得到的cate_id的最后一个逗号去掉!
还是用or效率应该更高一些吧,用in写起来更容易一些$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);
select * from table where cate_id in (2,4,8)把你得到的cate_id的最后一个逗号去掉!
$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);