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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
slaterino
Forum Commoner
Posts: 46
Joined: Fri Jul 11, 2008 10:50 am

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

Post 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
 
?>
Eric!
DevNet Resident
Posts: 1146
Joined: Sun Jun 14, 2009 3:13 pm

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

Post by Eric! »

The only way that could happen is if

Code: Select all

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