Jump to content

Archived

This topic is now archived and is closed to further replies.

jarvis

Simple IF ELSE Statement

Recommended Posts

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>&nbsp;</td><td>&nbsp;</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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites

×

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.