php mysq模糊查询l
2024-09-10 18:27:29
范例
<!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>
最新文章
- 遍历datatable的方法汇总
- c++ const 成员函数
- yii2 伪静态配置
- C#:比较二个字符串,查找出相同字数和差异字符
- Python自动化 【第十篇】:Python进阶-多进程/协程/事件驱动与Select\Poll\Epoll异步IO
- 用Perl编写Apache模块
- TForm的显示过程
- C# 打印小票 POS
- Silence.js高效开发移动Web前端类库
- c语言字符串翻转系列
- Imagine Cup 微软“创新杯”全球学生科技大赛
- JDK1.8源码阅读系列之四:HashMap (原创)
- Opengl4.5 中文手册—A
- 从零一起学Spring Boot之LayIM项目长成记(四) Spring Boot JPA 深入了解
- CAS 之 Https And Database Authentication(三)
- c/c++ 标准库 map set 删除
- 爬虫——scrapy框架
- 安装webpack和webpack打包(此文转自Henery)
- IP代理
- css3中的BFC,IFC,GFC和FFC