PHP中的多条件模糊查询

论坛 期权论坛 脚本     
匿名技术用户   2020-12-30 08:15   455   0
<?php
//获取查询条件
$wherelist = array();
if(!empty($_POST['title'])){
$wherelist[] = "title like '%{$_POST['title']}%'";
}
if(!empty($_POST['keywords'])){
$wherelist[] = "keywords like '%{$_POST['keywords']}%'";
}
if(!empty($_POST['content'])){
$wherelist[] = "content like '%{$_POST['content']}%'";
}
if(!empty($_POST['author'])){
$wherelist[] = "author like '%{$_POST['author']}%'";
}
//组装查询条件
if(count($wherelist) > 0){
$where = " where ".implode(' AND ' , $wherelist);
}
//判断查询条件
$where = isset($where) ? $where : '';
echo $where;
//得到查询条件
// $sql = "SELECT * FROM `table` '&where' ";
//$sql = "SELECT * FROM `table` {&where} ";
?>
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:7942463
帖子:1588486
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP