Page 1 of 1

Query not echo'ing contents of ELSE statement. Why?

Posted: Sun Aug 02, 2009 8:11 pm
by slaterino
Hi, I am slightly befuddled as my query is not returning anything in the ELSE statement. This is my query below. When the conditions of the IF statement are met it echo's the contents of that statement, but when the conditions are not met it does not show the contents of the ELSE statement. Why is this?

Code: Select all

$query = "SELECT contact_id, type_id FROM contact WHERE contact_id=$mye_id";
$result = mysql_query($query) or die('Error. ' . mysql_error());
while(list($contact_id, $type_id) = mysql_fetch_array($result))
 {
 if ($contact_id === $mye_id AND $type_id === '8')
  {
  echo "Contact Matches";
  
 
    } //end of IF matching statement
 
    else {
    echo "<p>Would you like to receive all of your references as official copies. If so, click below to pay for an Annual Subscription</p>";
    } //end of else statement
    
 
} //end of while loop
 
?>

Re: Query not echo'ing contents of ELSE statement. Why?

Posted: Mon Aug 03, 2009 7:46 am
by Eric!
The only way that could happen is if

Code: Select all

list($contact_id, $type_id) = mysql_fetch_array($result)
is empty