php mysq模糊查询l
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php mysq模糊查询l相关的知识,希望对你有一定的参考价值。
范例
<!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的主要内容,如果未能解决你的问题,请参考以下文章