范例

<!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的更多相关文章

  1. SQL SERVER 的模糊查询 LIKE

    今天写个动态脚本,需要把数据库里面包含“USER_"的表删除掉,突然想不起来如何搜索通配字符了,赶紧查查MSDN,整理了下模糊查询的知识点,留着以后查阅用. LIKE模糊查询的通配符 通配符 ...

  2. LIKE模糊查询的通配符

    LIKE模糊查询的通配符 通配符 说明 示例 % 包含零个或多个字符的任意字符串. WHERE title LIKE '%computer%' 将查找在书名中任意位置包含单词 "comput ...

  3. 2019-2-14sql server数据库模糊查询语句

    sql server数据库模糊查询语句   确切匹配: select * from hs_user where ID=123 模糊查询 select * from hs_user where ID l ...

  4. 一些不常用的Oracle用法记录(含模糊查询)

    (一).判断 某字段 是否包含 某字符串 select * from mc_member m where instr(m.bu, 'BU') > 0 --查询bu包含'BU' (二).将 某字段 ...

  5. Oracle--通配符、Escape转义字符、模糊查询语句

    一.通配符通配符描述示例      %:匹配包含零个或更多字符的任意字符串.WHERE title LIKE '%computer%' 将查找处于书名任意位置的包含单词 computer 的所有书名. ...

  6. stark组件的分页,模糊查询,批量删除

    1.分页组件高阶 2.整合展示数据showlist类 3.stark组件之分页 3.stark组件之search模糊查询 4.action批量处理数据 4.总结 1.分页组件高阶 1.分页的class ...

  7. instr()函数--支持模糊查询

    1)instr()函数的格式  (俗称:字符查找函数) 格式一:instr( string1, string2 )    /   instr(源字符串, 目标字符串) 格式二:instr( strin ...

  8. AJAX基本操作 + 登录 + 删除 + 模糊查询

    AJAX练习显示页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// ...

  9. 10 star组件之分页, search模糊查询, action批量处理

    1.分页组件高阶 1.分页的class形式(有bug,请看下面的) """ 自定义分页组件 """ class Pagination(obj ...

随机推荐

  1. VC 2008 Express下安装OpenCV2.3.1

    VC 2008 Express下安装OpenCV2.3.1   注意: 下列文档以VC2008 Express为例,VC2010下的配置应与本文档类似. VC 6.0不被OpenCV 2.3.1支持. ...

  2. 【LeetCode】30. Substring with Concatenation of All Words

    You are given a string, s, and a list of words, words, that are all of the same length. Find all sta ...

  3. [日记&做题记录]-Noip2016提高组复赛 倒数十天

    写这篇博客的时候有点激动 为了让自己不颓 还是写写日记 存存模板 Nov.8 2016 今天早上买了两个蛋挞 吃了一个 然后就做数论(前天晚上还是想放弃数论 但是昨天被数论虐了 woc noip模拟赛 ...

  4. 面试题-Java基础-面向对象

    1.面向对象软件开发的优点有哪些? 代码开发模块化,更易维护和修改.代码复用.增强代码的可靠性和灵活性.增加代码的可理解性.面向对象编程有很多重要的特性,比如:封装,继承,多态和抽象.下面的章节我们会 ...

  5. 【IE6的疯狂之七】样式中文注释后引发失效

    这是IE6 出现的奇怪现象.这是由于css 和html 的编码不同所引致. 满足下面条件就会引起 注释下面的样式不起作用:1. css有中文注释2. css为ANSI编码3. html为utf-8编码 ...

  6. Android抽屉效果 DrawerLayout 入门经验总结

    今天试了试这个抽屉布局的效果,结果很崩溃无语 网上很多资料都千篇一律,感觉都有问题,下面总结下几点经验: 先上个效果图: 1.  layout 布局文件中怎么写: <android.suppor ...

  7. hdu 5207 BestCoder Round #38 ($) Greatest Greatest Common Divisor

    #include<stdio.h> #include<string.h> #include<math.h> ]; ]; int main() { int sb; s ...

  8. Abstraction elimination

    (本文不保证不误人子弟,切勿轻信) Unlambda指的是lambda计算中去掉lambda操作(does not have lambda(or abstraction) operation of t ...

  9. transient关键字小结

    java中实现序列化有两种实现方式,一种是自动的,只要实现Serilizable接口,另一种是需要手动指定需要序列化的成员变量,实现Externalizable接口. transient的特点: 1. ...

  10. 最有用的Gulp插件汇总

    HTML&CSS autoprefixer - parse CSS and add vendor prefixes to rules by Can I Use. gulp-browser-sy ...