SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Zealot daemon's Avatar
    Join Date
    Apr 2001
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    "loop" through datetimes

    Hi,

    I have a table containing mysql datetimes.
    Now, for the sake of monthly statistics, I what to display some figures about the single months the page is online.
    I've gotten that far already:
    PHP Code:
                    $result query("SELECT dt FROM transaction ORDER BY dt LIMIT 1");
                    
    $online_since mysql_result($result0,0);
                    
                    
    $result query("SELECT dt FROM transaction ORDER BY dt desc LIMIT 1");
                    
    $online_thru mysql_result($result0,0); 
    Now, how can I loop through this timespan month wise?
    In the end I'm planing to do something like:
    query("SELECT SUM(items) FROM transacton WHERE dt LIKE '$loop_month%');

  2. #2
    PHP warrior dkode's Avatar
    Join Date
    Sep 2001
    Location
    Planet Namek
    Posts
    329
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't exactly understand what it is you are trying to do? are you going to run the results of the first query through another query? please be more descriptive and give a good example.
    "Mankind cannot define memory, yet it defines mankind"
    -- Project 2501, Ghost in the Shell

    Smarty | PEAR | PHP Manual | MySQL Manual

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First let's combine those queries.

    PHP Code:
    $result query("SELECT MAX(dt), MIN(dt) FROM transaction");
    $online_since mysql_result($result0,0);
    $online_thru mysql_result($result0,1); 

    Now if those are mysql datetime stamps, you can use strtomtime() on them to get them into a unix timestamp and use DATE() to show the Month name of each. Or you can get the month names from the query using DATE_FORMAT in the query.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •