本文目錄一覽:
- 1、PHp查找關鍵詞
- 2、php 該如何獲取從百度搜索進入網站的關鍵詞
- 3、ThinkPHP關鍵字搜索(從MySQL數據庫中)
- 4、php如何用關鍵字搜索MySQL當天的內容,求代碼
- 5、php mysql like 實現多關鍵詞搜索的方法
PHp查找關鍵詞
好像一句sql搞不定
$k = array();
$sql=’SELECT name FROM table’;
$r=mysql_query($sql);
while($row = mysql_fetch_row($sql)){
array_push($k, $row[0]);
}
foreach($k as $key=$val){
$k[$key] = “title LIKE ‘%”.$val.”%’ OR content LIKE ‘%”.$val.”%'”;
}
$sql=’SELECT id FROM table WHERE ‘.join(‘ OR ‘, $k);
$r=mysql_query($sql);
php 該如何獲取從百度搜索進入網站的關鍵詞
可以獲取到用戶跳轉時最後一次的鏈接,也就是你拿到用戶來源鏈接後,看看這裏面是否包含關鍵詞信息,如果不包含,那就沒辦法通過開發的方式實現。比如百度搜索,也許可以使用他們的網站統計服務來查看數據,但自己開發,可能不行。
像 MEZW搜索 這種直接跳轉的話,就沒問題,同樣獲取來源鏈接地址,然後從裏面提取關鍵詞即可。
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如何用關鍵字搜索MySQL當天的內容,求代碼
$today=strtotime(date(‘Y-m-d”));
$sql=”select * from table where title like “%關鍵詞%” and time.”$today;
php mysql like 實現多關鍵詞搜索的方法
或者叫,分詞檢索數據庫
$res
=
mysql_query(“select
*
from
peter
where
id
like
‘%中草藥%’
and
‘%6%'”);
//這樣寫是報錯的;
$res
=
mysql_query(“select
*
from
peter
where
id
like
‘%中草藥%’
or
‘%6%'”);
//而這樣寫是正確的;奇怪~
$res
=
mysql_query(“select
*
from
peter
where
id
like
‘%中草藥%’
and
id
like
‘%6%'”);
//這樣寫是正確的;
$res
=
mysql_query(“select
*
from
peter
where
id
like
‘%中草藥%’
or
id
like
‘%6%'”);
//這樣寫都是正確的;
以上就是小編為大家帶來的php
mysql
like
實現多關鍵詞搜索的方法全部內容了,希望大家多多支持腳本之家~
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/256966.html