我想驗證我的結果我從SQL查詢中獲得並檢查是否返回零結果我正在嘗試回顯相應的消息。然而,我正在努力做到這一點,我試圖使用if語句,但沒有工作的任何想法。以下是我的代碼。驗證來自mysql數據庫的結果
<?php
$mysql_query = "SELECT ISO_id, country_name, population, gdp, gold, silver, bronze, total FROM Country WHERE ISO_id='$countryID'";
$runmysql_query=mysql_query($mysql_query);
echo "<table class = 'table' border='4' align = 'center'>
<tr class = 'title'>
<th>ISOid</th>
<th>Country Name</th>
<th>Population</th>
<th>GDP</th>
<th>Gold</th>
<th>Silver</th>
<th>Bronze</th>
<th>Total</th>
</tr>"; //title headings declared
while($row = mysql_fetch_array($runmysql_query))
{
echo "<tr>";
echo "<td class = 'results'>" . $row['ISO_id'] . "</td>";
echo "<td class = 'results'>" . $row['country_name'] . "</td>";
echo "<td class = 'results'>" . $row['population'] . "</td>";
echo "<td class = 'results'>" . $row['gdp'] . "</td>";
echo "<td class = 'results'>" . $row['gold'] . "</td>";
echo "<td class = 'results'>" . $row['silver'] . "</td>";
echo "<td class = 'results'>" . $row['bronze'] . "</td>";
echo "<td class = 'results'>" . $row['total'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
你湊ld使用mysql的num rows函數。然後,如果返回0行,則打印該消息,否則打印數據。 http://php.net/manual/en/function.mysql-num-rows.php但mysql已棄用,因此您應該使用mysqli – sunrize920
請不要使用mysql_ *函數 - 它們已被棄用! – user4035