本文目錄一覽:
- 1、怎樣用php+mysql 做一個查詢的網頁
- 2、我要用戶PHP和資料庫做一個成績查詢系統。請問我應該怎麼做啊?不要太複雜
- 3、怎麼在網頁上用PHP做個搜索功能?
- 4、php怎麼做查詢
- 5、PHP查詢功能如何實現
怎樣用php+mysql 做一個查詢的網頁
首先搭建一個PHP環境,我用的wamp
然後比如你的資料庫位置是本地localhost
資料庫用戶名是root
資料庫密碼是123456
資料庫名是mydb
資料庫里有個表mytab
有3個欄位
id(主鍵) name sno
1 張三 123
2 李四 456
然後在項目根目錄,新建一個文件:index.php
?php
//連接資料庫
$con=mysqli_connect(“localhost”,”root”,”123456″,”mydb”);
//SQL語句
$sql=”select * from mytab;”;
//執行SQL語句,結果保存到$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實現最簡單的php網頁+mysql查詢功能/title
/head
body
?php
echo “pre”;
print_r($obj);
?
/body
/html
之後就能夠看到結果了
我要用戶PHP和資料庫做一個成績查詢系統。請問我應該怎麼做啊?不要太複雜
設計思路么?
首先你需要設計資料庫,成績查詢需要設計哪些表,最簡單的就是這幾三張表:學生表,課程表,成績表,然後設計每個表的欄位和關聯關係
然後寫代碼,對資料庫進行CURD,這種小系統完全不用考慮架構,數據量等,所以很簡單的,資料庫+PHP服務端+web前端 最多1天就差不多能做好了
怎麼在網頁上用PHP做個搜索功能?
通過from表單,將查詢的關鍵詞,通過 like 跟數據進行模糊查詢對比\x0d\x0a從topics表中查詢欄位subject與傳進來的參數’$_POST[‘topic’]進行比較模糊查詢\x0d\x0a設subject欄位數據為:數學,英語,物理,化學,英文\x0d\x0a$subject=$_POST[‘topic’]; \x0d\x0a$sql = “select * from topics where subject like ‘%” .$subject. “%'”;\x0d\x0a$result = mysql_query($sql);\x0d\x0a若從表單提交的『topic』值為「學」,得到的結果將是:數學,化學\x0d\x0a多個欄位匹配查詢:\x0d\x0a$sql = “select id,subject from topics where (id like ‘%” .$id. “%’) or (name like ‘%” .$name. “%’) or (subject like ‘%” .$subject. “%’) order by id desc”;\x0d\x0a結果依據欄位id的順序
php怎麼做查詢
form action=”” method=”post”
名字:input type=”text” name=”text”/
input type=”submit” name=”submit” value=”查詢”/
form
hr
?php$conn = mysql_connect(localhost,root,123456)
or die(‘沒有連接’);
$db = mysql_select_db(test,$conn) or die(‘沒有資料庫’);
mysql_query(“set names utf8”);
if(isset($_POST[‘submit’])){
$name=$_POST[‘text’];
$sql=”select * from ttt where name=”.$name.””;$tt=mysql_query($sql);if($tt){
$row = mysql_fetch_assoc($tt);
echo “名字:”.$row[name].”年齡:”.$row[age].”/br”;
}else{
return false;
}
}
其中:我的資料庫帳號是root 密碼是123456 資料庫是test 表名是ttt 表中有三個欄位 分別是id(主鍵 自增 ) name age 主要實現功能是你輸入一個名字 點擊查詢它會把這個人的信息就是名字和年齡顯示出來
PHP查詢功能如何實現
//獲得連接
$db = mysql_connect(“localhost”, “root”, “root”) or die(mysql_error());
//echo “Connected to MySQLbr/”;
//連接資料庫
mysql_select_db(“test”) or die(mysql_error());
//echo “Connected to Database”;
$result = mysql_query(“select * from books”,$db);
//循環遍歷
while ($myrow = mysql_fetch_row($result)){
print_r($myrow) ;
}
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/283133.html