Php 而查询不获取第一项
我的查询确实获得了项目,但不是全部。第一个不会被执行。我该怎么办Php 而查询不获取第一项,php,mysql,Php,Mysql,我的查询确实获得了项目,但不是全部。第一个不会被执行。我该怎么办 <?php $id = (int) $_SESSION['id']; $query = $conn->query ("SELECT * FROM transaction WHERE customerid = '$id' ") or die (mysqli_error()); $fetch = $query->fetch_array (); $customer_id=$fetch['customerid']; i
<?php
$id = (int) $_SESSION['id'];
$query = $conn->query ("SELECT * FROM transaction WHERE customerid = '$id' ") or die (mysqli_error());
$fetch = $query->fetch_array ();
$customer_id=$fetch['customerid'];
if($id!=$customer_id){
echo "<table>
<tr>
<td>No Order Yet!</td>
</tr>
</table>";
}else if($id==$customer_id){
while($row=$query->fetch_array ()){
echo"
\\code
";
}
}
?>
调用fetch\u array()
两次,就会错过第一条记录。如果我正确理解了您的逻辑,请尝试输出语句中的所有行,然后对空结果集进行额外检查
<?php
# Statement
$id = (int) $_SESSION['id'];
$query = $conn->query("SELECT * FROM transaction WHERE customerid = '$id' ") or die (mysqli_error());
# Rows output
while ($row = $query->fetch_array()) {
echo "";
}
# Empty result. Check record count after all the rows in the result have been retrieved.
if ($query->num_rows = 0) {
echo
"<table>
<tr><td>No Order Yet!</td></tr>
</table>";
)
?>
$query->fetch\u array()
one,$query->fetch\u array()
two。因为您已经在第5行获取了它。还要学习如何编写准备好的语句,因为您的代码容易受到SQL注入的攻击。您是否使用pdo或mysqli