这样每次添加where条件直接在数组中添加就好,不用更改具体的代码。
implode()的巧妙应用
if(intval($_GET['type']))
$where[]='type='.intval($_GET['type']);
else $where=null;
if(!intval($_GET['limit']))
$_GET['limit']=10;
if($_GET['category_id']<1)
$_GET['category_id']=1;
$where[]='category_id='.intval($_GET['category_id']);
if(intval($_GET['flag_ch']))
$where[]='flag_ch='.intval($_GET['flag_ch']);
$where1 = implode(' AND ', $where);
if ($topics_list = $this->model('topic')->get_topic_list($where1, $order,$_GET['limit'], $_GET['page']))
本文介绍了一种使用PHP进行数据库查询的高效方法,通过数组拼接WHERE条件,避免了直接修改代码来添加新的筛选条件,提高了代码的灵活性和可维护性。
448

被折叠的 条评论
为什么被折叠?



