SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Jul 2000
    Location
    North Central AR
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php/Mysql Select with date.

    I think I asked about this a little before, but still have yet to get it working.

    I have a php script that ads articles to a mysql db. One thing it adds is the date. The problem is, I neded to be able to pull records according to date. Mainly, say articles added in the last week, or ones added in the last month.

    I am not sure what is the best why to add the date to the record and more confusing how to pull the records according to recent like in the last week. I've tried reading on the php but think I got more confused.

    Any help would be greatly appreciated. Thanks in advance!

    ronnie
    The largest selection of PLR Articles on the Planet!
    Many Private Label Rights Products.

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I think that you should be able to use DATE_SUB (it's a built-in function in MySQL).
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    SitePoint Addict GeertDD's Avatar
    Join Date
    Feb 2005
    Location
    Belgium
    Posts
    334
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Something like this:
    Code:
    SELECT * FROM table WHERE date > (NOW() - INTERVAL 1 WEEK)

  4. #4
    SitePoint Addict
    Join Date
    Jul 2000
    Location
    North Central AR
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the replies so far!

    What would be the best way to insert the date?

    ronnie
    The largest selection of PLR Articles on the Planet!
    Many Private Label Rights Products.

  5. #5
    SitePoint Addict
    Join Date
    Jul 2000
    Location
    North Central AR
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried the code as follows:

    PHP Code:
    $sql "SELECT *
             FROM articles
             WHERE date_added > (NOW() - INTERVAL 1 WEEK)
             ORDER BY article_title"
    ;
     
    $sql_result mysql_query($sql$connection) or die("Could not query db to pull recent"); 
    But I get the connection error. The names for the fields are correct, db and table name correct.

    ronnie
    The largest selection of PLR Articles on the Planet!
    Many Private Label Rights Products.

  6. #6
    SitePoint Addict GeertDD's Avatar
    Join Date
    Feb 2005
    Location
    Belgium
    Posts
    334
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm sorry, you should try this:
    Code:
    SELECT * FROM table WHERE date > (NOW() - INTERVAL 7 DAY)

  7. #7
    SitePoint Addict
    Join Date
    Jul 2000
    Location
    North Central AR
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by GeertDD
    I'm sorry, you should try this:
    Code:
    SELECT * FROM table WHERE date > (NOW() - INTERVAL 7 DAY)
    Nothing to be sorry about. This second one works perfect! Thank you! Plus I can change the interval to what I want, when I want, so it works great for me. It's greatly appeciated..

    And lilleman, thanks for posting also.

    As usual sitepoint forums rock!

    ronnie
    The largest selection of PLR Articles on the Planet!
    Many Private Label Rights Products.


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
  •