我有一个从 mysql 表中提取信息的 php 脚本。如果脚本没有返回任何行,我想显示一条消息。
我努力了:
$numrows = mysql_num_rows($result);
if($numrows == 0)
{
echo "No entries";
}
else
{
//rest of code below
}
但它只返回一个错误,上面写着:
Warning: mysql_num_rows() expects parameter 1 to be resource, object given in /home/content/38/10473938/html/nhs_musical_blog/dashboard.php on line 211
我不明白,因为我在 stackoverflow.com 上找到了这段代码,提问者对这个答案非常满意,而且对他/她来说似乎工作得很好。我做错了什么才能得到糟糕的结果?
我的完整代码:(减去登录详细信息)
<?php
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM date_entries");
$numrows = mysql_num_rows($result);
if($numrows == 0)
{
echo "No entries";
}
else
{
echo "<ul class='mws-summary clearfix'>";
while($row = mysqli_fetch_array($result))
{
echo "<li>";
echo "<span class='key'>" . $row['name'] . "</span>";
echo "<span class='val'><span class='text-nowrap'>" . $row['date'] . "<a href='' target='_blank'><i class='icon-chevron-right pull-right' style='padding-top:5px;'></i></a>" . "</span></span>";
echo "</li>";
}
echo "</ul>";
mysqli_close($con);
}
?>