php在數(shù)據(jù)庫(kù)中搜尋數(shù)據(jù) php數(shù)據(jù)庫(kù)查詢系統(tǒng)

php如何搜索TXT數(shù)據(jù)庫(kù)內(nèi)信息?

這個(gè)簡(jiǎn)單的辦法,就是讀取文件,然后分析文件。

創(chuàng)新互聯(lián)建站主營(yíng)屯溪網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,app軟件開發(fā)公司,屯溪h5微信小程序搭建,屯溪網(wǎng)站營(yíng)銷推廣歡迎屯溪等地區(qū)企業(yè)咨詢

用到幾個(gè)函數(shù):file //?file() 將文件作為一個(gè)數(shù)組返回。數(shù)組中的每個(gè)單元都是文件中相應(yīng)的一行。

? ? ? ? ? ? ? ? ? explode//?explodef() ?分割字符串,用|分割

? ? ? ? ? ? ? ? ? 然后循環(huán)遍歷 判斷 展示就ok了。

例子://只作參考,沒有實(shí)際測(cè)試,如果還有疑問(wèn),請(qǐng)回復(fù)。

?php

$data?=?file('data.txt');

$post?=?$_POST['search'];

$str?=?'';

if($data??!empty($post))?{

foreach($data?as?$k?=?$v)?{

$row?=?explode('|',?$v);//array('name',?'age',?'sex');

$name?=?reset($row);//讀取數(shù)組的第一個(gè)元素

if($post?==?$name)?{

$str?=?$v;

break;

}

}

echo?$str;

}

?

php搜索查詢數(shù)據(jù)庫(kù)

1.action 后面的頁(yè)面沒有指定

2.if($name) 改成 if($name!=‘’)

3.把$sql 打印出來(lái)

4.頁(yè)面報(bào)錯(cuò)內(nèi)容是什么

完善上面4項(xiàng),糾錯(cuò)毫無(wú)壓力。

php搜索查詢數(shù)據(jù)庫(kù)數(shù)據(jù)

查看一下代碼:

?php

//?獲取表單提交值

$student_id?=?intval(trim($_POST['student_id']));

//?頁(yè)面表單??可以放單獨(dú)的html文件中,如果放單獨(dú)的html頁(yè)面中?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ù)提交時(shí)

if?($student_id)

{

$con=?mysql_connect("localhost","root","111")?or?die("連接錯(cuò)誤");

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é)號(hào):'.$row['student_id'].'br姓名:'.$row['name'].'br性別:'.$row['gender'].'br分?jǐn)?shù):'.$row['score'];

}

?

文章名稱:php在數(shù)據(jù)庫(kù)中搜尋數(shù)據(jù) php數(shù)據(jù)庫(kù)查詢系統(tǒng)
當(dāng)前URL:http://bm7419.com/article0/dohpeio.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)自適應(yīng)網(wǎng)站、網(wǎng)站導(dǎo)航、靜態(tài)網(wǎng)站、網(wǎng)站策劃

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁(yè)設(shè)計(jì)