Jump to content

what am I doing wrong, If while else


guymclaren

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.