Jump to content

Simple IF ELSE Statement


jarvis

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.