新聞中心
php 查詢 sql 數(shù)據(jù)庫 提取文章關(guān)鍵詞
$res=mysql_query("select
創(chuàng)新互聯(lián)堅持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的郊區(qū)網(wǎng)站設(shè)計、移動媒體設(shè)計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
*
from
keyword");//查找所有關(guān)鍵詞
while($row
=
mysql_fetch_array($rec)){//一次判斷,文章中有沒有出現(xiàn)該關(guān)鍵詞
$str
=
$row['name'];
$rec
=
mysql_query("select
*
from
文章表
where
$title
like
'%$str%'
or
$content
like
'%$str%'");//模糊查詢文章標(biāo)題和內(nèi)容中出現(xiàn)了的該關(guān)鍵詞的數(shù)據(jù)
$num
=
mysql_num_rows($rec);//文章標(biāo)題和內(nèi)容中出現(xiàn)了的該關(guān)鍵詞的文章條數(shù)
if($num){
echo
$str;
}
}
php通過mysql like搜索關(guān)鍵詞查詢,所有符合數(shù)據(jù)遍歷出來
?php
$host="localhost";
$username="root";
$password="root";
$db="db4"; //庫名
$mysql_table="person"; //表名
//連接數(shù)據(jù)庫,面向過程
$conn=mysqli_connect($host,$username,$password);
if(!$conn){
echo "數(shù)據(jù)庫連接失敗";
exit;
}
//選擇所要操作的數(shù)據(jù)庫
mysqli_select_db($conn,$db);
//設(shè)置數(shù)據(jù)庫編碼格式
mysqli_query($conn,"SET NAMES UTF8");
//編寫sql獲取分頁數(shù)據(jù) SELECT * FROM 表名 LIMIT 起始位置,顯示條數(shù)
//注意:以下id,name,age,say都是字段節(jié)點名,person是表名,db4是數(shù)據(jù)庫名,think是指定的關(guān)鍵字.
$sql = 'SELECT id, name, age, say
FROM person
WHERE say LIKE "%think%" order by id ASC LIMIT '.($page-1)*$pageSize .",{$pageSize}";
// 節(jié)點名 關(guān)鍵字 節(jié)點名 可指定數(shù)量limit后可寫一個指定的數(shù)字
//$sql="select * from $mysql_table"
//把sql語句傳送到數(shù)據(jù)庫
$result=mysqli_query($conn,$sql);
//將數(shù)據(jù)顯示到table中,并未table設(shè)置格式
echo "div class='content'";
echo "table border=1 cellspacing=0 width=30% align=center";
echo "trtdID/tdtdNAME/tdtdsay/td/tr";
while ($row = mysqli_fetch_assoc($result)) {
echo "tr";
echo "td{$row['id']}/td";
echo "td{$row['name']}/td";
echo "td{$row['say']}/td";
echo "tr";
}
echo "/table";
echo "/div";
//釋放結(jié)果
mysqli_free_result($result);
//關(guān)閉數(shù)據(jù)庫
mysqli_close($conn);
ThinkPHP關(guān)鍵字搜索(從MySQL數(shù)據(jù)庫中)
提交的時候記得把默認(rèn)的值去掉? 才能判斷是否有值..
//這個是把三個搜索關(guān)鍵詞作為獨立的因子搜索
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);
}
}
//以下是把三個搜索當(dāng)作條件進(jìn)行搜索??有篩選的味道
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關(guān)鍵詞查詢數(shù)據(jù)庫 php關(guān)鍵字的意思
網(wǎng)站路徑:http://biofuelwatch.net/article/ddgohgh.html