slaterino Posted August 3, 2009 Share Posted August 3, 2009 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 ?> Link to comment https://forums.phpfreaks.com/topic/168571-query-not-echoing-contents-of-else-statement-why/ Share on other sites More sharing options...
phpSensei Posted August 3, 2009 Share Posted August 3, 2009 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. Link to comment https://forums.phpfreaks.com/topic/168571-query-not-echoing-contents-of-else-statement-why/#findComment-889207 Share on other sites More sharing options...
abazoskib Posted August 3, 2009 Share Posted August 3, 2009 $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. Link to comment https://forums.phpfreaks.com/topic/168571-query-not-echoing-contents-of-else-statement-why/#findComment-889211 Share on other sites More sharing options...
phpSensei Posted August 3, 2009 Share Posted August 3, 2009 $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.. Link to comment https://forums.phpfreaks.com/topic/168571-query-not-echoing-contents-of-else-statement-why/#findComment-889223 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.