范例

<!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>
 

最新文章

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

热门文章

  1. WIN10使用管理员权限运行VS2013
  2. Python批量重命名
  3. trove 开发者阅读翻译
  4. 修改cookie
  5. 使用signalR创建聊天室。
  6. CountDownLatch使用详解
  7. Form标签+Css基础
  8. 常用的html标签大全
  9. ansible role 执行顺序
  10. 【IE6的疯狂之一】IE6中奇数宽高的BUG