半点优化网 http://www.bdxc.net/
当前位置首页 > 关键词排名> 正文

php多关键字查询怎么实现?

2021-06-25 00:47:46 暂无评论 188 关键词排名 数据库   内容   查询

$_keywords = $_GET['q'];
$key       = explode(' ', $_keywords );
if ( sizeof( $key ) == 1 ) {
   $where  = " title like '%{$_keywords}%' ";
} else {
   froeach( $key as $word ) {
     $k[] = " title like '%{$word}%' ";
   }
   $where = join(' or ', $k );
}
$sql = "select * from news where status = 1 and ({$where}) and catid = 23 order by id desc";

php查询数据库内容

$content = '电脑店 联想';
$Key     = explode(' ', $content); //打散成数组
foreach( $key as $k =>  $val ) {
  $Like .= !$k ? " 关键词 like '%{$val}%' " : " or  关键词 like '&{$val}&' ";
}   
$Sql = "select * from 表 wehre {$Like}";

//查询sql自己写

猜你喜欢