Javascript 第一行数据未放入表php
当我查看数据库中的记录时。第一条记录没有显示在页面上。当我添加第二条记录并打开时,它们将显示在页面上,但我输入的第一条记录除外。我不知道这是为什么。我附上了我试过的代码Javascript 第一行数据未放入表php,javascript,php,Javascript,Php,当我查看数据库中的记录时。第一条记录没有显示在页面上。当我添加第二条记录并打开时,它们将显示在页面上,但我输入的第一条记录除外。我不知道这是为什么。我附上了我试过的代码 $last\u insert\u id=$\u GET['last\u id']此id来自购买页面。获取id并将select语句和view relevent记录与id匹配 $sql = "select i.pur_id,i.prod_id,i.buyprice,i.qty,i.total,p.date,p.total,p.pay
$last\u insert\u id=$\u GET['last\u id']代码>此id来自购买页面。获取id并将select语句和view relevent记录与id匹配
$sql = "select i.pur_id,i.prod_id,i.buyprice,i.qty,i.total,p.date,p.total,p.pay,p.due from purchase_item i, purs p where i.pur_id = p.id and i.pur_id = '278' ";
278 id中包含7行数据,但仅显示6行
<?php
$x = 1;
$last_insert_id = $_GET['last_id'];
$sql = "select i.pur_id,i.prod_id,i.buyprice,i.qty,i.total,p.date,p.total,p.pay,p.due from purchase_item i, purs p where i.pur_id = p.id and p.id = $last_insert_id ";
$orderResult = $conn->query($sql);
$orderData = $orderResult->fetch_array();
while ($row = $orderResult->fetch_array()) {
?>
<tr>
<td class="text-center">
<?php echo $x; ?>
</td>
<td class="text-center">
<?php echo $row[6]; ?>
</td>
<td class="text-center">
<?php echo $row[3]; ?>
</td>
<td class="text-center"><?php echo $row[2]; ?></td>
<td class="text-right"><?php echo $row[4]; ?></td>
</tr>
<?php
$x++;
}
?>
此处:$orderData=$orderResult->fetch_array()
您将第一行提取到$orderData
中,因此当您对SQL注入非常开放时,它将在循环中被跳过:您不能在SQL查询中使用原始用户输入。请看一看准备好的语句如何编写,先生?只需删除这一行$orderData=$orderResult->fetch_array()代码>那一行只读取结果集的第一行,与之无关。谢谢,先生,工作正常