SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A simple IF statement

    I cannot get the simplest IF statement to work and I don't know if I am missing something obvious. The code below will not echo the statements even when "April" is in the db:
    -----------------------------------

    $query2 = "SELECT * FROM Rates WHERE Month = 'April' ORDER BY Start";
    if ($Month == "April") {

    echo"<tr><td colspan='5' bgcolor='#4682b4'>&nbsp;<b><font size='2'>&nbsp;</font><font size='2' color='white' face='Verdana, Arial, Helvetica, sans-serif'>April</font></b></td></tr>";


    $result2 = mysql_query($query2)
    or die ("Sorry, there is another problem with the web site at this time.");
    while ($row2 = mysql_fetch_array($result2))
    {
    $Start = "";
    $End = "";
    $Rate = "";
    $Available = "";
    extract($row2);
    echo"<tr><td width='20%'>&nbsp;</td><td width='20%'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>$Start</font></td><td width='20%'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>$End</font></td><td width='20%'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>$Rate</font></td><td width='20%'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>$Available</font></td></tr>";

    }
    }

    ----------------------------
    Help this crosseyed coder! Nantucketer

  2. #2
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Error: Insufficient code.

    PHP Code:
          $query2 "SELECT * FROM Rates WHERE Month = 'April' ORDER BY Start";
          if (
    $Month == "April") { 
    Where is $Month set?

    Are you looking for something like:

    PHP Code:
     <?php
     $query2 
    "SELECT * FROM Rates WHERE Month = 'April' ORDER BY Start";
     
    $result2 mysql_query($query2)
     if (
    mysql_num_rows($result2) > 0) {
         
    //...
     
    }
     
    ?>
    My name is Steve, and I'm a super-villian.

  3. #3
    Level 8 Chinese guy Archbob's Avatar
    Join Date
    Sep 2001
    Location
    Somewhere in this vast universe
    Posts
    3,741
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So, why are you selecting where month='April' and then making sure $Month==April again on the very next line? Did you actually specify a value for $Month somewhere on the page?

  4. #4
    Accredited Master scotty2260's Avatar
    Join Date
    Apr 2004
    Location
    California
    Posts
    423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I assume you just used the April as an example, or else you are doing error checking for nothing. You need to set $month to the mon that you grabbed.
    PHP Code:
    $query2 "SELECT * FROM Rates WHERE Month = 'April' ORDER BY Start";
    $result mysql_query($sql);
    $row mysql_fetch_array($result);
    extract($row);
    // This is assuming the column where the month is stored is actaully name 'month'
    if ($Month == "April") {

    echo
    "<tr><td colspan='5' bgcolor='#4682b4'>&nbsp;<b><font size='2'>&nbsp;</font><font size='2' color='white' face='Verdana, Arial, Helvetica, sans-serif'>April</font></b></td></tr>";


    $result2 mysql_query($query2)
    or die (
    "Sorry, there is another problem with the web site at this time.");
    while (
    $row2 mysql_fetch_array($result2))
    {
    $Start "";
    $End "";
    $Rate "";
    $Available "";
    extract($row2);
    echo
    "<tr><td width='20%'>&nbsp;</td><td width='20%'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>$Start</font></td><td width='20%'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>$End</font></td><td width='20%'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>$Rate</font></td><td width='20%'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>$Available</font></td></tr>";

    }

    Scott

  5. #5
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    That sounds like it

    I will try your suggestion - I think I have not sufficiently defined the $Month field. - will let you know.

    Thanks

  6. #6
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile

    This worked - I knew it was something obviously simple! I made the following adjustment:

    $query2 = "SELECT * FROM Rates WHERE Month = 'April' ORDER BY Start";
    $result = mysql_query($query2);
    while ($row = mysql_fetch_array($result))
    {
    extract($row);
    if ($Month == "April") {

    echo"<tr><td colspan='5' bgcolor='#4682b4'>&nbsp;<b><font size='2'>&nbsp;</font><font size='2' color='white' face='Verdana, Arial, Helvetica, sans-serif'>April</font></b></td></tr>";

    }
    $result2 = mysql_query($query2)
    or die ("Sorry, there is another problem with the web site at this time.");
    while ($row2 = mysql_fetch_array($result2))
    {
    $Start = "";
    $End = "";
    $Rate = "";
    $Available = "";
    extract($row2);
    echo"<tr><td width='20%'>&nbsp;</td><td width='20%'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>$Start</font></td><td width='20%'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>$End</font></td><td width='20%'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>$Rate</font></td><td width='20%'><font size='2' face='Verdana, Arial, Helvetica, sans-serif'>$Available</font></td></tr>";

    }
    }

  7. #7
    La la la la la bronze trophy lieut_data's Avatar
    Join Date
    Jun 2003
    Location
    Waterloo, ON
    Posts
    1,517
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by nantucketer
    This worked - I knew it was something obviously simple! I made the following adjustment:
    Ehmmm... that code is wrong on so many levels...

    Back to ArchBob's point:

    Quote Originally Posted by ArchBob
    So, why are you selecting where month='April' and then making sure $Month==April again on the very next line?
    My name is Steve, and I'm a super-villian.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •