PHP文本數(shù)據(jù)庫的搜索方法
10年積累的做網(wǎng)站、網(wǎng)站建設(shè)經(jīng)驗,可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識你,你也不認(rèn)識我。但先做網(wǎng)站設(shè)計后付款的網(wǎng)站建設(shè)流程,更有安圖免費網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
searchstr=("/".preg_quote($searchstr)."/");
//$searchstr是查找的關(guān)鍵字
$records=file($file);//獲取所有的記錄數(shù)
//$file是查找的數(shù)據(jù)文件
$search_reocrds=preg_grep
($searchstr,
$records);//開始查找記錄
//$search_reocrds為查找到的記錄數(shù)
unset($records);
if($search_records){
//開始顯示記錄,寫下你自己的處理程序********************
while
(list
($key,
$val)
=
each
(
$search_records))
{
echo
"$val
";
}
//****************************************************
}
下面是首頁顯示數(shù)據(jù)表package中的內(nèi)容,但是有個條件,顯示在首頁的內(nèi)容還必須是 :字段status=0,且printing=0的數(shù)據(jù)才能在首頁列表中顯示出來。
頁面上有一個“搜索”功能,輸入條件后就會根據(jù)條件來進行查詢。
一般的搜索的話,只要在首頁顯示列表方法index()中給一個:
?
$map=array();//初始化查詢條件
$map=$this-_search();//調(diào)用查詢方法
$total = $this-Model-where ($map)-count(); //這個主要是用來計算頁面顯示數(shù)據(jù)條數(shù)的
if ($total == 0) {
$_list = '';
} else {
$_list = $this-Model-where ($map)-limit( $post_data ['first'] . ',' . $post_data ['rows'] )-select();
}
然后,就是寫一個_search():
protected function _search(){
$map = array ();
$post_data = I ( 'post.' );
if ($post_data ['packageid'] != '') {
$map ['packageid'] = array (
'like',
'%' . $post_data ['packageid'] . '%'
);
}
return $map;
}
最后,在設(shè)置的“搜索”菜單中,調(diào)用這個搜索方法。
但是,這個搜索的.同時,還要確保在字段status=0,且printing=0的數(shù)據(jù)中進行搜索。
這個限制條件該加在什么地方。各種嘗試和查詢后,才知道。限制條件直接加在SQL語句中就行了(如下紅色的地方)。(我自己試的時候一直在如下藍色的地方加條件,屢試屢敗!)
$map=array();
$map=$this-_search();
$total = $this-Model-where ($map)-where(array('status' =0,'print_status'=0))-count();
if ($total == 0) {
$_list = '';
} else {
$_list = $this-Model-where ($map)-where(array('status' =0,'print_status'=0))-limit( $post_data ['first'] . ',' . $post_data ['rows'] )-select();
}
更多相關(guān)文章推薦:
查看一下代碼:
?php
//?獲取表單提交值
$student_id?=?intval(trim($_POST['student_id']));
//?頁面表單??可以放單獨的html文件中,如果放單獨的html頁面中?form?的action的地址要改成下面的PHP文件名
echo?'form?action=""?method="post"
input?type="text"?name="student_id"?value="{$student_id}"/
input?type="submit"?name="submit"?value="查詢"/
/form';
//?當(dāng)有數(shù)據(jù)提交時
if?($student_id)
{
$con=?mysql_connect("localhost","root","111")?or?die("連接錯誤");
mysql_select_db("examination",$con);
//?查詢
$sql?=?"SELECT?*?FROM?tablename?WHERE?student_id?=?$student_id?";
$res=mysql_query($sql);
$row=mysql_fetch_array($res);
//?輸出
echo?'學(xué)號:'.$row['student_id'].'br姓名:'.$row['name'].'br性別:'.$row['gender'].'br分?jǐn)?shù):'.$row['score'];
}
?
網(wǎng)站題目:數(shù)據(jù)檢索php 數(shù)據(jù)檢索庫有哪些
網(wǎng)頁URL:http://jinyejixie.com/article2/ddcojic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、ChatGPT、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站設(shè)計、App開發(fā)、微信公眾號
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)