여기 날짜로 검색 할 때이 프로젝트를 만들고 있습니다. 결과가 없으면 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 = mysqli_num_rows 같은 결과의 행 수를 계산하는
mysqli_num_rows()
을 사용할 수 있습니다 $ result);'$ num> 0인지 확인하십시오. – krishnahttp://www.php.net/manual/en/mysqli-result.num-rows.php –
... 감사합니다! – Smoke