mysql 多条件查询问题
select * from subcatalog where name like '%$keywords%' and catalog = $catalog order by rank $rank limit $pages, $rows
上面的语句,怎么可以做到当 $catalog 这个值为空的时候,可以搜索其他的数据,现在这里catalog = $catalog 为空的时候列表就没有东西出来了
分享到: 更多
------解决方案--------------------
思路这样子的,语法自己调整下:
if($catalog==''){
$tiaojian = '';
}else{
$tiaojian = and catalog = $catalog;
}
$sql = select * from subcatalog where name like '%$keywords%' $tiaojian order by rank $rank limit $pages, $rows