【发布时间】:2017-02-18 02:32:27
【问题描述】:
我想知道是否可以查询数据库,并且每次单击提交按钮时,它都会向表中添加一个新行,而不是刷新页面。
你看,发生的事情是当我运行查询时,它会成功添加行,但是当我再次运行查询时,它会刷新页面,基本上一次只能添加一行。
基本上,我希望能够创建一个表格,每次我使用条码扫描仪扫描条码时都会将产品添加到列表中。当用户扫描代码时,将执行查询从数据库中获取相关数据,并显示一行。
$barcode = $_POST["Barcode"];
$query = "Select * from products WHERE ProductBarcode = $barcode";
$result = $mysqli->query($query);
if ($result->num_rows > 0) {
echo "<table>
<tr>
<td><strong>ID</strong></td>
<td><strong>Name</strong></td>
</tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td><input type='checkbox' value='".$row['Row_ID']."' />".$row['Row_ID']."</td>
<td>".$row['ProductName']." "."</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
$mysqli->close();
【问题讨论】:
-
您可能需要使用 Jquery 或 Javascript 来实现此目的而无需刷新页面