Jump to content


Photo

If statement - hair pull out *SOLVED*


  • Please log in to reply
3 replies to this topic

#1 highaspen

highaspen
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 23 September 2006 - 06:12 PM

okay, I've tried writting this several different ways each not working. I'm sure it's something stupid. Here is what I've got.

------------------------
$rs=mysql_query($sql,$conn)
or die("Could not execute query");

if (!$rs){
include ("somepage.php");
exit();}

else{ then I've got a bunch of code here. }
------------------------

The problem I'm having is, the if statment is continually ignored and only displays the else. I've rigged the database so that the if statment will be true, yet it still fails. I've also tried this using if ($rs == "null") with the same results. And if($rs==NULL).

Any help would place the helper in GOD status in my mind.

Thanks

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,023 posts

Posted 23 September 2006 - 06:28 PM

mysql_query only returns false if the query fails beacause of an error.

Are you expecting $rs to be false because no records are returned. Returning no records is not an error. To check that condition you need

<?php
$rs=mysql_query($sql,$conn)
      or die("Could not execute query");
      
if (mysql_num_rows($rs)==0){
    include ("somepage.php");
    exit();
}

else { 
        // then I've got a bunch of code here. 
}
?>


If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 highaspen

highaspen
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 23 September 2006 - 06:42 PM

You're a God... thanks.

#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,023 posts

Posted 23 September 2006 - 06:47 PM

The only ambrosia I get to eat is rice pudding :)
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users