MySQL query help...

Discussion in 'PHP' started by jijihuqw, Jun 15, 2011.

  1. #1
    Hi,

    I have this situation on my hands, I need to display only todays links from the db, but the db table shows a row called date_added and the date is specified as month day, year format: Ex: June 12, 2011. How can I output only the rows with 'todays' date? Meaning tomorrow will be June 13, 2011, so only those will be on the page etc..

    Thank you
     
    jijihuqw, Jun 15, 2011 IP
  2. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #2
    So you're asking how to return tuples that have an attribute with the current day?

    If so, as far as I'm aware, you will need to use a programming language to generate the value that represents the current day following the same syntax as the date_added attribute.

    Since you posted this in PHP, this is what I would do:

    
    <?php
    
    // Database connection goes here
    // Mysql_connect(), mysql_select_db() etc..
    
    $today = date('F j, y'); // Look up this PHP function
    mysql_query("SELECT [I]wantedAttributes[/I] FROM [I]tableName[/I] WHERE date_added = '$today'") or die ("Error: ".mysql_error());
    
    mysql_close();
    
    ?>
    
    Code (markup):
    Here's the function you need to be familiar with: Date()

    I hope this helps!
     
    Last edited: Jun 15, 2011
    BRUm, Jun 15, 2011 IP