我想根據查詢是否爲null來判斷條件,並打印兩個不同的表。以下是我的代碼。檢查一個MYSQL查詢是否爲空
$number_of_date= "SELECT SUM(number_of_date) AS number_of_date
FROM emp_leaves
WHERE emp_id='$userID'
AND leave_category='Annual'
AND apply_year='$year'";
$number_date = mysql_query ($number_of_date);
if (($number_date == 'NULL'))
{
$result2 = "SELECT * FROM leave_info
WHERE employment_type='permanent'
AND leave_type='annual'";
$sql2 = mysql_query ($result2);
while($row = mysql_fetch_array($sql2)) {
?>
<tr>
<td><?php echo $row["leave_type"]?></td>
<td><?php echo $row["leave_count"]?></td>
</td></tr><?php }
}
else
{
$sql = "SELECT * FROM emp_leaves
WHERE emp_id='$userID'
AND leave_category='Annual'
ORDER BY leave_id DESC limit 1";
$result = mysql_query ($sql);
while($row = mysql_fetch_array($result)) {
?>
<tr>
<td><?php echo $row["leave_category"]?></td>
<?php }?><?php
while($row11 = mysql_fetch_array($number_date)) {
?>
<td><?php echo $row11["number_of_date"]?></td><?php } } ?>
</tr>
但是,「如果」條件不起作用。做出這種狀況的正確方法是什麼?任何人都請幫助我!
我已更新ans請檢查 –