include("connect.php");
$SQL="SELECT * FROM promo ";
$run=mysql_query($SQL,$con) or die ("SQL error");
$rec=mysql_fetch_array($run);
首先,我想检查这个查询是否给出了空记录。 如果它不输出任何记录,应打印“表中没有记录” 否则使用while循环打印所有记录。 我可以使用while循环显示记录。困难的是检查输出是否为空。检查提取数组的空洞
请帮我做到这一点。谢谢
echo "<table border='1' align='center' >";
echo "<tr> <th> Room ID </th> <th> Start Date </th> <th> End Date </th> <th> Promo Rate </th> </TR>";
$run=mysql_query($SQL2,$con) or die ("SQL2 error");
while($rec2=mysql_fetch_array($run))
{
echo "<tr>";
echo "<td>".$rec2['roomid']."</td>";
echo "<td>".$rec2['startdate']."</td>";
echo "<td>".$rec2['enddate']."</td>";
echo "<td>".$rec2['rate']."</td>";
echo "</tr>";
}
echo "</table>";
所以运行'如果(空())'在while循环。 N.B .: NULL!=空应该有NULL值。或运行一个num_rows并检查。或者数()很多方法来做到这一点。 –
如果没有行'mysql_fetch_array'返回'false'。 –
请不要使用[mysql_'数据库扩展名](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php),它不推荐使用 (永远不会使用在PHP7中) 特别是,如果你只是学习PHP,花费你的精力学习'PDO'数据库扩展。 [从这里开始](http://php.net/manual/en/book.pdo.php) – RiggsFolly