SELECT WHERE statement problem

Discussion in 'PHP' started by bfeller, Dec 10, 2007.

  1. #1
    I have a SELECT WHERE statement that I am having issues with. Below is the code that is causing the problem. Granted, probably not the cleanest code (still learning), but for the most part it works.

    
    $result3 = mysql_query('SELECT date FROM ongoing ORDER BY ID DESC LIMIT 1');
    $datadate = mysql_fetch_row($result3);
    $datadate = $datadate[0];
    
    $result14 = mysql_query('SELECT MAX(outdoortempF) FROM ongoing WHERE date="$datadate"');
    $maxtemp = mysql_fetch_row($result14);
    $maxtemp = $maxtemp[0];
    
    PHP:

    The first section works just as expected (returns the DATE (YYYY-MM-DD) from the date field in the database).

    The second section is where I am having trouble. I can't seem to get the date="$datadate" part to work. The code simply returns nothing. On the other hand, if I type in the date so it reads date="2007-12-10", the code works perfectly. In addition, if I try echo "$datadate" it returns 2007-12-10.

    How can I get it to pull "outsidetempF" data only from rows where the date = today?

    Thanks!
     
    bfeller, Dec 10, 2007 IP
  2. sm9ai

    sm9ai Active Member

    Messages:
    746
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    60
    #2
    This might help

    $result14 = mysql_query('SELECT MAX(outdoortempF) FROM ongoing WHERE date="'.$datadate.'"');
    $maxtemp = mysql_fetch_row($result14);
    $maxtemp = $maxtemp[0];

    If you have trouble with queires echo it out.

    echo 'SELECT MAX(outdoortempF) FROM ongoing WHERE date="'.$datadate.'"';

    and see if it comes out as expected with all the varialbles.
     
    sm9ai, Dec 11, 2007 IP
  3. bfeller

    bfeller Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Perfect. Thank you for the solution!
     
    bfeller, Dec 11, 2007 IP