标签:
范例
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>模糊查询条件设置</title>
</head>
<body>
<form action="form.php" method="post">
标题:<input type="text" name="title" value="<?php if(isset($_POST[‘title‘])) echo $_POST[‘title‘] ?>"/>
关键字: <input type="text" name="keywords" value="<?php if(isset($_POST[‘keywords‘])) echo $_POST[‘keywords‘] ?>"/>
内容: <input type="text" name="content" value="<?php if(isset($_POST[‘content‘])) echo $_POST[‘content‘ ]?>"/>
作者: <input type="text" name="author" value="<?php if(isset($_POST[‘author‘])) echo $_POST[‘author‘] ?>"/>
<input type="submit" value="搜索...">
<input type="button" value="清除历史" onclick="window.location=‘form.php‘">
</form>
<?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} ";
?>
</body>
</html>
php mysq模糊查询l
标签:
原文地址:http://www.cnblogs.com/lidepeng/p/5352493.html