Jump to content

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


slaterino

Recommended Posts

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?

 

$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

?>

if ($contact_id === $mye_id AND $type_id === '8')

 

^^ incorrect

 

if (($contact_id == $mye_id)&&($type_id == '8'))

 

^^ correct

 

 

$query = "SELECT contact_id, type_id FROM contact WHERE contact_id=$mye_id";

 

 

^^ incorrect

 

$query = "SELECT `contact_id`, `type_id` FROM `contact` WHERE `contact_id`='$mye_id'";

 

^^ correct

 

 

Check if $mye_id is correct or outputs anything. Try printing it out.

$query = "SELECT contact_id, type_id FROM contact WHERE contact_id=$mye_id";

 

 

^^ incorrect

 

$query = "SELECT `contact_id`, `type_id` FROM `contact` WHERE `contact_id`='$mye_id'";

 

^^ correct

 

Not quite. Either would work. Formatting with the ` character is personal preference.

$query = "SELECT contact_id, type_id FROM contact WHERE contact_id=$mye_id";

 

 

^^ incorrect

 

$query = "SELECT `contact_id`, `type_id` FROM `contact` WHERE `contact_id`='$mye_id'";

 

^^ correct

 

Not quite. Either would work. Formatting with the ` character is personal preference.

 

Its also a good practice to place them..

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.