jarvis Posted May 24, 2006 Share Posted May 24, 2006 Hi,I've got trouble with a really simple IF ELSE statement, it works fine if theirs a value in the db, but the ELSE part of the statement doesn't function. Am going insane trying to work it out. Any help would be superb![code]$query1 ="SELECT associations.a_id, events.event_id,events.event, associations.month_id,DATE_FORMAT(months.date,'%d %M %Y') as date FROM months INNER JOIN (events INNER JOIN associations ON events.event_id = associations.event_id) ON months.month_id = associations.month_id WHERE ((associations.month_id) BETWEEN '32' AND '59')";$result1 = mysql_query ($query); echo "<tr> <td align=\"left\">February</td><td> </td><td> </td>"; echo'</tr>'; while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) { if ($query >= 0) { echo'<tr>'; echo'<td>' . $row['event'] . '</td><td>' . $row['date'] . '</td>'; echo "<td><a href=\"event_info.php?uid=" . $row['event_id'] . " \">details</a></td>"; echo'</tr>'; }else{ echo "<tr> <td colspan=\"3\">no events this month</td> </tr>"; } }[/code]Is it something stupid I'm overlooking? The query works fine. Using another form, if I enter data, specific to a particular month, then the data is displayed. If I remove it, it should say 'no events this month'. But just appears blank.Any help gratefully receievd!jarvis Quote Link to comment https://forums.phpfreaks.com/topic/10350-simple-if-else-statement/ Share on other sites More sharing options...
AndyB Posted May 24, 2006 Share Posted May 24, 2006 Are you quite sure you have $query and $query1 and $result and $result1 all just the way they need to be? Or is your code slightly different from what you posted? Quote Link to comment https://forums.phpfreaks.com/topic/10350-simple-if-else-statement/#findComment-38579 Share on other sites More sharing options...
jarvis Posted May 24, 2006 Author Share Posted May 24, 2006 Sorry, it's just where I've put the code in here! They should all be $query1 or $result1, that's what I've got on my PC. its just where I was using $query3 and $result3 for the third variation of testing on my PC and thought it'd put them to 1's to prevent confusion. Instead, created confusion! Quote Link to comment https://forums.phpfreaks.com/topic/10350-simple-if-else-statement/#findComment-38584 Share on other sites More sharing options...
AndyB Posted May 24, 2006 Share Posted May 24, 2006 [code] if ($query >= 0) { [/code]Whether it's $query or $query1 it will never be negative (and it's defined a few lines earlier). That's the logic problem: maybe you want to check the number of rows returned by the query and if that's zero there are no results. Quote Link to comment https://forums.phpfreaks.com/topic/10350-simple-if-else-statement/#findComment-38595 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.