本文目錄一覽:
如何用php獲取資料庫信息並顯示
獲取ppq資料庫的所有表名的代碼:
?php
$server=’localhost’;
$user=’root’;
$pass=’12345′;
$dbname=’ppq’;
$conn=mysql_connect($server,$user,$pass);
if(!$conn)
die(“資料庫系統連接失敗!”);
$result=mysql_list_tables($dbname);
if(!$result)
die(“資料庫連接失敗!”);
while($row=mysql_fetch_row($result))
{
echo
$row[0].”
“;
}
mysql_free_result($result);
?
mysql_list_tables
(PHP
3,
PHP
4
,
PHP
5)
mysql_list_tables
—
列出
MySQL
資料庫中的表
說明
resource
mysql_list_tables
(
string
database
[,
resource
link_identifier])
mysql_list_tables()
接受一個資料庫名並返回和
mysql_query()
函數很相似的一個結果指針。用
mysql_fetch_array()或者用mysql_fetch_row()來獲得一個數組,數組的第0列就是數組名,當獲取不到時
mysql_fetch_array()或者用mysql_fetch_row()返回
FALSE。
php如何查詢資料庫表中的數據並顯示
這個簡單啊!
首頁做個前台輸入姓名和會員卡信息的頁面,我做個簡單的頁面給你看
!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會員查詢系統/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″,”資料庫用戶名”,”資料庫密碼”);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}
$a = mysql_select_db(“資料庫名字”, $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顯示所有資料庫
如果想全部顯示 就需要循環顯示
你的錯誤在於 $db = mysql_fetch_row($sdb)
你把這個改成 while($db = mysql_fetch_row($sdb)){rows[] =$db;}
$db = mysql_fetch_row($sdb)
因為只會取一個
PHP 怎麼顯示資料庫中的數據 求源代碼
讀資料庫,以表格輸出的示例代碼:
?php
header(‘Content-type:text/html;charset=utf-8’);
$db = new mysqli(‘localhost’,’root’,’root’,’books’);
$rows = $db-query(‘SELECT * FROM customers’);
echo ‘table border=”1″trtd姓名/tdtd年齡/td/tr’;
while($row = $rows-fetch_assoc()){
echo ‘trtd’.$row[‘name’].’/td’;
echo ‘td’.$row[‘address’].’/td/tr’;
}
?
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/239844.html