新聞中心
php如何查詢數(shù)據(jù)庫表中的數(shù)據(jù)并顯示
這個簡單?。?/p>
專注于為中小企業(yè)提供成都網(wǎng)站設(shè)計、做網(wǎng)站服務(wù),電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)來安免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了上1000+企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(shè)實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。
首頁做個前臺輸入姓名和會員卡信息的頁面,我做個簡單的頁面給你看
!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?"
html?xmlns="
head
meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/
title會員查詢系統(tǒng)/title
/head
body
form?id="form1"?name="form1"?method="post"?action="test.php"
p
label?for="name"/label
input?type="text"?name="name"?id="name"?/
/p
p
label?for="vipid"/label
input?type="text"?name="vipid"?id="vipid"?/
/p
p
input?type="submit"?name="button"?id="button"?value="查詢"?/
/p
/form
/body
/html
然后我給你一個test.php的文件代碼:
?php
$name????=????trim($_POST['name']);
$vipid????=????trim($_POST['vipid']);
$con?=?mysql_connect("127.0.0.1","數(shù)據(jù)庫用戶名","數(shù)據(jù)庫密碼");
if?(!$con)
{
die('Could?not?connect:?'?.?mysql_error());
}
$a????=????mysql_select_db("數(shù)據(jù)庫名字",?$con);
$sql????=????"select?*?from?kh_customer?where?name?=?'$name'?and?vipid?=?'$vipid'";
$result?=?mysql_query($sql);
while($row?=?mysql_fetch_array($result))
{
echo?$row['name']?.?"?"?.?$row['data'];
echo?"br?/";
}
mysql_close($con);
?
頁面美化自己去搞!只能幫你這么多了
怎樣利用php獲取數(shù)據(jù)庫中指定的記錄
這是PHP獲取數(shù)據(jù)庫信息的代碼 希望能給你帶來啟發(fā)
?php
$conn=mysql_connect("localhost","root","");
$select=mysql_select_db("books",$conn);
$query="insert into computers(name,price,publish_data) ";
$query.="values('JSP',28.00,'2008-11-1')";
$query="select * from computers";
$result=mysql_query($query);
//以下是使用mysql_result()函數(shù)來獲取到查詢結(jié)果
$num=mysql_num_rows($result);
for($rows_count=0;$rows_count$num;$rows_count++){
echo "書名:".mysql_result($result,$rows_count,"name");
echo "價格:".mysql_result($result,$rows_count,"price");
echo "出版日期:".mysql_result($result,$rows_count,"publish_data")."br";
}
//以下是使用mysql_fetch_row()函數(shù)來獲取到查詢結(jié)果
while($row=mysql_fetch_row($result))
{
echo "書號:".$row[0]."br";
echo "書名:".$row[1]."br";
echo "價格:".$row[2]."br";
echo "出版日期:".$row[3]."br";
echo "br";
}
//以下是使用mysql_fetch_array()函數(shù)來獲取到查詢結(jié)果
while($row=mysql_fetch_array($result))
{
echo "書號:".$row[0]."br";
echo "書名:".$row[1]."br";
echo "價格:".$row["price"]."br";
echo "出版日期:".$row["publish_data"]."br";
echo "br";
}
//以下是使用mysql_fetch_object()函數(shù)來獲取到查詢結(jié)果
while($row=mysql_fetch_object($result))
{
echo "書號:".$row-id."br";
echo "書名:".$row-name."br";
echo "價格:".$row-price."br";
echo "出版日期:".$row-publish_data."br";
echo "br";
}
?
用PHP代碼如何查詢數(shù)據(jù)庫表中的一條記錄
我直接在這給你修改答案算了
使用的時候刪除行號
修改數(shù)據(jù)庫配置
如果想使用
頁面不刷新查詢數(shù)據(jù)庫
需要使用JQUERY
如果有需要給我留言
1
?php
2
if(isset($_POST['submit'])$_POST['submit']=='提交'){
3
//判斷是否是提交過來的
4
$intext
=
$_POST['intext'];
5
if($intext!=null||$intext!=''){
6
$link
=
mysql_connect("localhost",
"root",
"123456");
7
//數(shù)據(jù)庫配置信息
第一個參數(shù)數(shù)據(jù)庫位置第二個是用戶名第三個是密碼
8
mysql_select_db("szn_test");
9
//設(shè)置要使用的數(shù)據(jù)庫
10
$sql
=
"select
*
from
demo
where
res
=
'".$intext."'";
11
//SQL語句
12
var_dump($sql);
13
$res
=
mysql_query($sql);
14
$arr
=
array();
15
//吧結(jié)果存入數(shù)組
并記錄數(shù)組長度
16
$count
=
0;
17
while($data
=
mysql_fetch_array($res)){
18
$arr[$count]
=
$data;
19
$count++;
20
}
21
//關(guān)閉數(shù)據(jù)庫
22
mysql_close($link);
23
}
24
}
25
26
?
27
html
28
head
29
title/title
30
/head
31
body
32
form
id="form1"
method="post"
action="demo.php"
33
input
type="text"
name="intext"
34
input
type="submit"
name="submit"
value="提交"
35
/form
36
?php
37
if(isset($arr)$arr
!=
null){
38
for($i
=
0;
$i
$count;
$i++){
39
foreach($arr[$i]
as
$key
=
$value){
40
echo
"key:".$key."
value:".$value;
41
echo
"
";
42
}
43
echo
"br";
44
}
45
}
46
?
47
/body
48
/html
這個是數(shù)據(jù)庫查詢代碼
你可以看以下對照著修改修改
求助:在php中,怎么才能知道數(shù)據(jù)庫(mysql)的表里面一共有多少條記錄???
如果是客戶端連接數(shù)據(jù)庫的話,一條語句OK。select count(*) from tablename;
?php
$conn=mysql_connect('localhost','root','password');//連接數(shù)據(jù)庫
mysql_select_db('databasename',$conn);//選擇要查詢的數(shù)據(jù)庫
$sql="select count(*) from tablename";//SQL查詢語句
if($result=mysql_query($sql,$conn))
{
$aaa=mysql_fetch_row($result);
echo $aaa[0]; //輸出表里面總記錄數(shù)
}
網(wǎng)頁題目:php怎么看數(shù)據(jù)庫記錄 php判斷數(shù)據(jù)表記錄是否存在
轉(zhuǎn)載來于:http://www.dlmjj.cn/article/dodhocs.html