我有以下声明,IF ELSE似乎不起作用?通过不工作我的意思是它只是运行while循环并显示H1而不检查结果是否为空?
有人能看到任何明显错误吗?
if($interests_result != 0) {
print "<h1>Users with the same interests!</h1><div style='clear:both;'>";
while($interests_row = mysql_fetch_array($interests_result, MYSQL_ASSOC))
{
$int_user = $interests_row['user_id'];
$int_twit_user = $interests_row['twitterUser'];
$divLeft = '<div class="user-box" id="thediv_'.$int_user.'"><div class="twithandlepic"><img src="http://api.twitter.com/1/users/profile_image/';
$divRight = '<div class="twithandle">';
$clearDiv = '<div style="clear:both;"></div>';
print $divLeft.strip_tags($int_twit_user)."?size=normal\" style=\"width:48px; height:48px;\"/><br \/>".$int_twit_user.$divRight."<a href='javascript:void(0);' id='".$interests_row['user_id']."' class='getIntPoint'>Get ".$interests_row['coff']." <input type='hidden' value='".$interests_row['coff']."' class='credoff' name='credoff'/> credit(s)</a><br /></div>$clearDiv</div></div>";
}
print $clearDiv."</div>";
}
else
{
print "No users to display!";
}
分配给interests_result的值是......
$interests_query = "SELECT * FROM produgg_users
join user_interests on produgg_users.id = user_interests.user_id
where (interest = '$interest1' OR interest = '$interest2' OR interest = '$interest3') and produgg_users.id != '".$usersClass->userID()."' and credits >= coff and produgg_users.id NOT IN (select concat_ws(',', followedID) from produgg_activity where followerID = '".$usersClass->userID()."') ORDER BY coff DESC LIMIT 30;";
$interests_result = mysql_query($interests_query) or die(mysql_error());
答案 0 :(得分:4)
$interests_result
是一个mysql资源。它不等于0,($interests_result != 0
为真),因此正在执行if
的块。
您想要检查的是:
if (mysql_num_rows($interests_result) != 0) {
答案 1 :(得分:1)
mysql_query()
会在成功时返回资源,如果错误则返回 FALSE ,而不是0
答案 2 :(得分:1)
答案 3 :(得分:0)
您想检查返回的行数。