2011-07-07 14 views
0

次のような声明がありますが、IF ELSEは機能していないようですか?私はそれがちょうどwhileループを実行し、結果がヌルでないかどうかをチェックせずにH1を表示することを意味していませんか?IF文は機能しますが、ELSEは機能しません。

明らかなエラーは誰でも見ることができますか?

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()); 
+1

あなたは '$ interests_result'にどのような価値を割り当てていますか? – Quentin

+0

IveがQuentinを更新しました... – Liam

答えて

4

$interests_resultはmysqlリソースです。 0に等しくないため($interests_result != 0が真)、ifのブロックが実行されています。

if (mysql_num_rows($interests_result) != 0) { 
+0

Ahh thankyouあまりにも多くの@nickf、私はそれを知りませんでした... – Liam

1

mysql_queryリターンを成功にリソースを返し、エラー時にはFALSE 、どちらかではありませんリソースまたはFALSE(エラーがある場合)

返される行の数が含まれていると思われるように見えますが、そうではありません。

あなたの比較のためにmysql_num_rowsを使用してください。

0

あなたが返される行数をチェックしたい:あなたの代わりにチェックすることにしたいどのような

はこれです。

関連する問題