search.html //前臺網(wǎng)頁編寫
創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供通江網(wǎng)站建設(shè)、通江做網(wǎng)站、通江網(wǎng)站設(shè)計、通江網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、通江企業(yè)網(wǎng)站模板建站服務(wù),10年通江做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
html
head
meta http-equiv="Content-Type"content="text/html;charset=gb2312"
title搜索/title
/head
body
form name="form" action="search.php" method="post"
input type="text" name="search_text" size="20"
input type="submit" value="搜索"
/form
/body
/html
search.php//后臺處理文件
?php
$word=$_POST["search_text"];
$link=mysql_connect("localhost","root","password") or die("無法連接");
//localhost、root和password需要根據(jù)自己的實際情況來使用。
$db_selected=mysql_select_db("db_keywords",$link);
//db_keywords為要打開的數(shù)據(jù)庫。
$sql="select * from keywords where word like '%$word%' order by count desc";
//keywords為要打開查詢的表
$result=mysql_query($sql,$link);
while($row=mysql_fetch_row($result))
{
for($i=0;$imysql_num_fields($result);$i++)
echo "$row[$i]"." ";
echo "br";
}
?
這是最簡單也是具有最基本功能的搜索頁面,其他的需要自己修改和處理了。
希望對你有所幫助。
首先搭建一個PHP環(huán)境,我用的wamp
然后比如你的數(shù)據(jù)庫位置是本地localhost
數(shù)據(jù)庫用戶名是root
數(shù)據(jù)庫密碼是123456
數(shù)據(jù)庫名是mydb
數(shù)據(jù)庫里有個表mytab
有3個字段
id(主鍵) name sno
1 張三 123
2 李四 456
然后在項目根目錄,新建一個文件:index.php
?php
//連接數(shù)據(jù)庫
$con=mysqli_connect("localhost","root","123456","mydb");
//SQL語句
$sql="select * from mytab;";
//執(zhí)行SQL語句,結(jié)果保存到$arr
$obj=mysqli_query($con,$sql);
$arr=mysqli_num_rows($result);
?
html
head
meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
title實現(xiàn)最簡單的php網(wǎng)頁+mysql查詢功能/title
/head
body
?php
echo "pre";
print_r($obj);
?
/body
/html
之后就能夠看到結(jié)果了
$db = mysql_connect("localhost", "root", "password");
mysql_select_db("mydb",$db);
if (isset($_POST['name'])) {
echo "你輸入的用戶是:". $_POST['name'];
}
$result = mysql_query("SELECT * FROM employees WHERE name='".$_POST['name']."'",$db);
while ($fields = mysql_fetch_row($result)) {
$data[] = $filelds;
}
if(!empty($data)){
foreach($data as $val){
foreach($val as $k = $v){
echo $k." ".$v."br /";
}
echo "br /hr /";
}
}else{
echo "此用戶下沒有數(shù)據(jù)。";
}
可能需要修改的地方,查詢條件我是使用的name,根據(jù)你數(shù)據(jù)庫中的字段名做一下更改,輸出信息沒有太多的處理,可以使用表格輸出或是其它樣式,可以自己調(diào)整一下,HTML部分省略了。
通過from表單,將查詢的關(guān)鍵詞,通過 like 跟數(shù)據(jù)進行模糊查詢對比
從topics表中查詢字段subject與傳進來的參數(shù)'$_POST['topic']進行比較模糊查詢
設(shè)subject字段數(shù)據(jù)為:數(shù)學,英語,物理,化學,英文
$subject=$_POST['topic'];
$sql = "select * from topics where subject like '%" .$subject. "%'";
$result = mysql_query($sql);
若從表單提交的‘topic’值為“學”,得到的結(jié)果將是:數(shù)學,化學
多個字段匹配查詢:
$sql = "select id,subject from topics where (id like '%" .$id. "%') or (name like '%" .$name. "%') or (subject like '%" .$subject. "%') order by id desc";
結(jié)果依據(jù)字段id的順序
設(shè)計思路么?
首先你需要設(shè)計數(shù)據(jù)庫,成績查詢需要設(shè)計哪些表,最簡單的就是這幾三張表:學生表,課程表,成績表,然后設(shè)計每個表的字段和關(guān)聯(lián)關(guān)系
然后寫代碼,對數(shù)據(jù)庫進行CURD,這種小系統(tǒng)完全不用考慮架構(gòu),數(shù)據(jù)量等,所以很簡單的,數(shù)據(jù)庫+PHP服務(wù)端+web前端 最多1天就差不多能做好了
當前題目:php做數(shù)據(jù)查詢網(wǎng)頁 php獲取網(wǎng)頁數(shù)據(jù)
網(wǎng)頁路徑:http://chinadenli.net/article8/doddoop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站制作、軟件開發(fā)、搜索引擎優(yōu)化、面包屑導航、小程序開發(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)