我正在尝试使用数据库的结果并将其显示在HTML表中。我已经四处搜索但是找不到具体的答案,因为我是PHP的新手,我不得不从其他来源复制此代码,因为我无法让它独立完成。请帮忙。
<?php $server = "127.0.0.1";
$user = "admin";
$pass = "password";
$dbname = "hysteryalelogs";
// Create connection in mysqli
$connection = new mysqli($server, $user, $pass, $dbname);
//Check connection in mysqli
if($connection->connect_error){
die("Error on connection:" .$connection->connect_error);
}
//Display the informaion
$sql = "SELECT * FROM logs";
$res = $connection->query($sql);
if($res->num_rows > 0){
while($row = $res->fetch_assoc()){
echo "Sales Number: ". $row["Sales_Number"]. "<br/>";
echo "Quantity: ". $row["Quantity"]. "<br/>";
echo "Due Date: ". $row["Due_Date"]. "<br/>";
echo "Burnished Housing: ". $row["Burnished"]. "<br/>";
echo "Greased Bearings: ". $row["Grease"]. "<br/>";
echo "Air Cleaned: ". $row["Air"]. "<br/>";
echo "SS Screw: ". $row["Screw"]. "<br/>";
echo "Test Date: ". $row["Test_Date"]. "<br/>";
echo "Pass: ". $row["Pass"]. "<br/>";
echo "Fail: ". $row["Fail"]. "<br/>";
echo "Tester: ". $row["Tester"]. "<br/>";
echo "Final Check: ". $row["Final_Check"]. "<br/>";
echo "Green Dot: ". $row["Green_Dot"]. "<br/>";
echo "Green Dot Check: ". $row["Green_Dot_Check"]. "<br/>";
echo "Ship Date: ". $row["Ship_Date"]. "<br/>";
echo "Serial Number: ". $row["Serial_Number"]. "<br><br><hr><br/>";
}
} else {
echo "No Record Found!";
}
$connection->close();
?>
(澄清)代码有效。我只是不知道如何格式化表格以便在里面显示。
答案 0 :(得分:0)
嗨:)希望这会有所帮助:)
{{1}}