189 8069 5689

php数据库搜索关键字 php关键字查询

PHP中怎么实现关键字搜索?

PHP要实现关键字查搜索,需要用到like关键字来组合查询条件

成都创新互联公司始终坚持【策划先行,效果至上】的经营理念,通过多达十余年累计超上千家客户的网站建设总结了一套系统有效的全网营销解决方案,现已广泛运用于各行各业的客户,其中包括:成都茶艺设计等企业,备受客户好评。

like具体实现方法如下:

例一:

1    $userForm=M('user');    

1    $where['name']=array('like','phpernote%');    

2    $userForm-where($where)-select();

这里的like查询即为:name like 'phpernote%'

例二:

1$where['name']=array('like',array('%phpernote%','%.com'),'OR');

这里的like查询即为:name like '%phpernote%' or name like '%.com'

例三:

1$where['name']=array(array('like','%a%'),array('like','%b%'),array('like','%c%'),'phpernote','or');

这里的like查询即为:(`name` LIKE '%a%') OR (`name` LIKE '%b%') OR (`name` LIKE '%c%') OR (`name` = 'phpernote')

例四:

1$where['_string']='(name like "%phpernote%")  OR (title like "%phpernote")'

这里的like查询即为:name like '%phpernote%' or title like '%phpernote'

ThinkPHP关键字搜索(从MySQL数据库中)

提交的时候记得把默认的值去掉  才能判断是否有值..

//这个是把三个搜索关键词作为独立的因子搜索

function search(){

if(isset($_POST['id'])  intval($_POST['id'])0){

$sql="select * from tbl  where id=".intval($_POST['id'])." ";

}

if(isset($_POST['name'])){

$sql.="union select * from tbl where name=".$_POST['name']." ";

}

if(isset($_POST['content'])){

$sql.="union select * from tbl where content like '%".$_POST['content']."%' ";

}

$s = M('search');

$result=$s-query($sql);

}

}

//以下是把三个搜索当作条件进行搜索  有筛选的味道

function search(){

$where="1=1";

if(isset($_POST['content'])){

$where.=" and content like '%$_POST[content]%'";

}

if(isset($_POST['content'])){

$where.=" and name = '$_POST[name ]'";

}

if(isset($_POST['id'])  intval($_POST['id'])0){

$where.=" and id= '$_POST[id]'";

}

if($where != '1=1'){

$sql="select * from tbl $where";

}else{

throw new Exception('没有输入搜索词');

}

$s = M('search');

$result=$s-query($sql);

}

}

php简单关键字搜索功能,谁能帮我把代码写一下

$sql=“select * from 数据表 where 查询的关键字 like %要查询的数据内容%”;


当前名称:php数据库搜索关键字 php关键字查询
当前地址:http://cdxtjz.cn/article/dopegij.html

其他资讯