gpt4 book ai didi

php - 输出应该是找不到数据

转载 作者:行者123 更新时间:2023-11-29 13:13:58 26 4
gpt4 key购买 nike

当我按日期搜索时,我正在为此创建一个项目。如果没有结果,我想输出no data found。但这里如果没有结果我就得到表格格式。如果数据显示就OK了!但有一个问题是数据库中没有数据。

 <?php
include('connect.php');
?>
<?php
// echo $res;
$result = mysqli_query($con,"SELECT * FROM buyer where date='$res'");
//$result = mysqli_query($con, "SELECT * FROM buyer WHERE date='09-01-14'");

if($result==NULL)
{
echo "no data found";
}
else{
echo "<table class='CSSTable'>

<tr>
<th>invoice no</th>
<th>Buyer Name</th>
<th>Buyer Order number</th>
<th>Date</th>
<th>Total Amount</th>
<th>Total Items</th>
<th>Generate PDF</th>
</tr>";

while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['invoice_number'] . "</td>";
echo "<td>" . $row['buyer_name'] . "</td>";
echo "<td>" . $row['buyer_order_number'] . "</td>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['total_amount'] . "</td>";
echo "<td>" . $row['total_items'] . "</td>";
echo "<td>" ." <a href='get_pdf.php?id={$row['invoice_number']}' target='_blank'><img src='image/download.png' width='16' height='16' /></a>" . "</td>";
echo "</tr>";
}

echo "</table>";
}

mysqli_close($con);
?>

最佳答案

您应该使用 num_rows 检查结果中返回的行数。 。就像这样:

if(!$result->num_rows)
{
echo "no data found";
}

num_rows 将始终返回整数行数。

关于php - 输出应该是找不到数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21727725/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com