【发布时间】:2016-08-28 07:03:09
【问题描述】:
我有这个表格元素,代码如下:
<?php
if(isset($_POST["submit"])){
if (strlen($cIdMsg = 0) && strlen($cFirstNameMsg = 0) && strlen($cLastNameMsg = 0) && strlen($pCodeMsg = 0)) {
require_once("conn.php");
$sql2 = "SELECT * FROM customer;";
$results = mysqli_query($conn, $sql2)
or die ('Problem with query' . mysqli_error($conn));
echo "no errors found";
}
}
?>
<table>
<tr>
<th>Customer ID</th>
<th>FIrst Name</th>
<th>Last Name </th>
</tr>
<?php
while ($row = mysqli_fetch_array($results)) { ?>
<tr>
<td><?php echo $row["customerID"]?></td>
<td><?php echo $row["firstName"]?></td>
<td><?php echo $row["lastName"]?></td>
</tr>
<?php } ?>
</table>
在这张表的上方,我有一个 php 代码,它在 if isset 条件内进行 sql 查询,以便它仅在按表单上的提交后加载。我想对桌子做同样的事情。那就是只有在按下提交后才加载。因为在页面加载时它试图在一个不存在的 $result 上执行 mysqli_fetch_array
【问题讨论】:
-
发布你的完整代码!!
-
您想使用 Ajax 请求在后台获取数据并仅在获得查询结果时插入行?