|
<?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} ";
?> |