关于如何插入到 html 表中的具体信息
Posted
技术标签:
【中文标题】关于如何插入到 html 表中的具体信息【英文标题】:Specific information on how to insert into html table 【发布时间】:2018-05-20 20:08:17 【问题描述】:我正在尝试使用数据库的结果并将它们显示在 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();
?>
(澄清)代码有效。我只是不知道如何格式化表格以使其显示在里面。
【问题讨论】:
还有几十万人已经成功地发布了代码。所以我怀疑是你的错误,而不是网站 好像我们要接受所有这些。 我现在感觉不太聪明 @Brian 应该为此获得一枚奖牌。 ***.com/revisions/47682841/5 这不是一个新手友好的地方。我们都希望每个人都尽职尽责地学习如何发布和使用该网站。事情就是这样。 【参考方案1】:嗨 :) 希望这会有所帮助 :)
<?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)
echo "<table border='3px' cellpadding='5px' cellspacing='5px' align='center' bgcolor='skyblue' ";
echo "<tr>";
echo "<td><center><strong>Sales Number</strong></center></td>";
echo "<td><center><strong>Quantity</strong></center></td>";
echo "<td><center><strong>Due Date</strong></center></td>";
echo "<td><center><strong>Burnished Housing</strong></center></td>";
echo "<td><center><strong>Greased Bearings</strong></center></td>";
echo "<td><center><strong>Air Cleaned</strong></center></td>";
echo "<td><center><strong>SS Screw</strong></center></td>";
echo "<td><center><strong>Test Date</strong></center></td>";
echo "<td><center><strong>Pass</strong></center></td>";
echo "<td><center><strong>Fail</strong></center></td>";
echo "<td><center><strong>Tester</strong></center></td>";
echo "<td><center><strong>Final Check</strong></center></td>";
echo "<td><center><strong>Green Dot</strong></center></td>";
echo "<td><center><strong>Green Dot Check</strong></center></td>";
echo "<td><center><strong>Ship Date</strong></center></td>";
echo "<td><center><strong>Serial Number</strong></center></td>";
echo "</tr>";
while($row = $res->fetch_assoc())
echo "<tr>";
echo "<td>"."<center>"."<i>".$row["Sales_Number"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Quantity"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Due_Date"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Burnished"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Grease"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Air"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Screw"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Test_Date"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Pass"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Fail"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Tester"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Final_Check"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Green_Dot"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Green_Dot_Check"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Ship_Date"]."</i>"."</center>"."</td>";
echo "<td>"."<center>"."<i>".$row["Serial_Number"]."</i>"."</center>"."</td>";
echo "</tr>";
echo "</table>";
else
echo "No Record Found!";
$connection->close();
?>
【讨论】:
不客气 :)以上是关于关于如何插入到 html 表中的具体信息的主要内容,如果未能解决你的问题,请参考以下文章
如何使用 PHP、SQL 和 Microsoft Access 将另一个表中的 select max 函数和用户输入的变量插入表中?