Jump to content

Recommended Posts

I am trying to create an alternative if the answer is NULL, How or what am I doing wrong?

 

 


   1. If ($status == 0){
   2.             $sqlq="SELECT * FROM cocats INNER JOIN companies ON companies.id = cocats.co WHERE cocats.cat='".$cat." AND companies.status = '3' ORDER BY RAND() LIMIT 0,3";
   3.             $objRS = mysql_query($sqlq);
   4.         while($row = mysql_fetch_array($objRS, MYSQL_ASSOC)) {
   5.         $status = $row["status"];
   6.             $profile = $row['profile'];
   7.             }
   8.             If ($row == Null) {
   9.                 $sqlq="SELECT * FROM companies WHERE status = '3' ORDER BY RAND()LIMIT 0,3";}
  10.                 $objRS = mysql_query($sqlq);
  11.                 while($row = mysql_fetch_array($objRS, MYSQL_ASSOC)) {
  12.                 $status = $row["status"];
  13.                 $profile = $row['profile']
  14.                 }
  15.             }

 

Link to comment
https://forums.phpfreaks.com/topic/184890-what-am-i-doing-wrong-if-while-else/
Share on other sites

$row cannot be NULL, your while loop will only be entered if $row doesn't evaluate to FALSE (which NULL does). The only value that can be NULL is a field in the $row array, such as $row['status'].

 

OK so if I have no results, how do I change my query, you see if I say if status == Null then it gives me the true loop and adds the false loop at the end.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.