Jump to content


Photo

Simple IF ELSE Statement


  • Please log in to reply
3 replies to this topic

#1 jarvis

jarvis
  • Members
  • PipPipPip
  • Advanced Member
  • 420 posts

Posted 24 May 2006 - 02:20 PM

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!
$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>";
    }
  }

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

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 24 May 2006 - 02:42 PM

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?
Legend has it that reading the manual never killed anyone.
My site

#3 jarvis

jarvis
  • Members
  • PipPipPip
  • Advanced Member
  • 420 posts

Posted 24 May 2006 - 02:47 PM

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!

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 24 May 2006 - 03:12 PM

   if ($query >= 0) {
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.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users