我正在尝试将此PHP SQL查询的输出放置到数据库表中,但是它将所有行数据输出到一列中.if(isset($_POST[submit])) {$name = htmlentities($_POST[name]);$parts = explode( , $name);$lastname = array_pop($par...

我正在尝试将此PHP SQL查询的输出放置到数据库表中,但是它将所有行数据输出到一列中.
if(isset($_POST['submit'])) {
$name = htmlentities($_POST['name']);
$parts = explode(" ", $name);
$lastname = array_pop($parts);
$firstname = implode(" ", $parts);
$connection = mysql_connect("localhost", "user", "password");
mysql_select_db("shoretoshore", $connection);
$result = mysql_query("SELECT ship_no, shipment_id, arrival_date, origin, destination, lname, fname from shipment, captain WHERE captain.capt_id=shipment.capt_id AND captain.fname='$firstname' AND captain.lname='$lastname'", $connection);
echo '<table border="0" cellpadding="5px" cellspacing="1px" style="font-family:Verdana, Geneva, sans-serif; font-size:11px; background-color:#E1E1E1" width="100%">
<tr bgcolor="#FFFFFF" style="font-weight:bold">
<th>Shipment No.</th>
<th>Shipment Id.</th>
<th>Arrival Date</th>
<th>Origin</th>
<th>Destination</th>
<th>Last Name</th>
<th>First Name</th>
</tr>';
while ($row = mysql_fetch_row($result)) {
foreach ($row as $value)
print "<tr><td>"."{$value}"."</td></tr>";
echo "<br>";
}
echo "</table>";
}
如何将查询结果输出到HTML表中?
解决方法:
您将$value放在引号内,它将被视为字符串.
尝试:
while ($row = mysql_fetch_row($result)) {
echo '<tr>';
foreach ($row as $value)
{
echo "<td>".$value."</td>";
}
echo "</tr>";
}
织梦狗教程
本文标题为:php-将sql查询输出到html表中


基础教程推荐
猜你喜欢
- 前端Website sitemap.xml文件搜索引擎优化 2023-07-09
- 探讨Ajax中的一些小问题 2022-12-28
- Vue使用NProgress 2023-10-08
- 关于 html:如何在单选按钮旁边显示文本? 2022-09-21
- 通过Ajax方式绑定select选项数据的实例 2023-02-22
- ajax+springmvc实现C与View之间的数据交流方法 2023-01-31
- 基于bootstrap的上传插件fileinput实现ajax异步上传功能(支持多文件上传预览拖拽) 2023-01-31
- AJAX请求数据及实现跨域的三种方法详解 2023-02-23
- VUE中实现跨域访问后台方法获取JSON数据 2023-10-08
- HTML5实战与剖析之触摸事件(touchstart、touchmove和touchend) 2022-11-16