本文目錄一覽:
php怎麼把數據表橫向展示
這個很簡單的,先說個比較容易理解的方法
將while循環方式修改下即可。
echo(‘trtdname/td’);
while($row = mysqli_fetch_array($result)){
echo(‘td’.$row[‘name’].’/td’);
}
echo(‘/tr’);
echo(‘trtdgender/td’);
while($row = mysqli_fetch_array($result)){
echo(‘td’.$row[‘gender’].’/td’);
}
echo(‘/tr’);
echo(‘trtdage/td’);
while($row = mysqli_fetch_array($result)){
echo(‘td’.$row[‘age’].’/td’);
}
echo(‘/tr’);
怎麼用php顯示mysql 數據表數據
html
head
title瀏覽表中記錄/title
/head
body
center
?php
$db_host=localhost; //MYSQL服務器名
$db_user=root; //MYSQL用戶名
$db_pass=””; //MYSQL用戶對應密碼
$db_name=”test”; //要操作的數據庫
//使用mysql_connect()函數對服務器進行連接,如果出錯返回相應信息
$link=mysql_connect($db_host,$db_user,$db_pass)or die(“不能連接到服務器”.mysql_error());
mysql_select_db($db_name,$link); //選擇相應的數據庫,這裡選擇test庫
$sql=”select * from test1″; //先執行SQL語句顯示所有記錄以與插入後相比較
$result=mysql_query($sql,$link); //使用mysql_query()發送SQL請求
echo “當前表中的記錄有:”;
echo “table border=1”; //使用表格格式化數據
echo “trtdID/tdtd姓名/tdtd郵箱/tdtd電話/tdtd地址/td/tr”;
while($row=mysql_fetch_array($result)) //遍歷SQL語句執行結果把值賦給數組
{
echo “tr”;
echo “td”.$row[id].”/td”; //顯示ID
echo “td”.$row[name].” /td”; //顯示姓名
echo “td”.$row[mail].” /td”; //顯示郵箱
echo “td”.$row[phone].” /td”; //顯示電話
echo “td”.$row[address].” /td”; //顯示地址
echo “/tr”;
}
echo “/table”;
?
/center
/body
/html
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);
?
頁面美化自己去搞!只能幫你這麼多了
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hk/n/151151.html