Results 1 to 6 of 6

Thread: MySQL Grouping

  1. #1
    Join Date
    Apr 2006
    Posts
    190
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default MySQL Grouping

    Right now I have this query

    Code:
    SELECT DISTINCT YEAR(dt) AS 'Year', MONTH(dt) AS 'Month', DAY(dt) AS 'Day', `dt`, `description` FROM webcalendar_events_ver4 GROUP BY YEAR(dt), MONTH(dt) ORDER BY dt ASC
    Which out puts this:

    January 2008
    2008-01-19 Testing the admin panel today
    But I want this

    January 2008
    2008-01-19 Testing the admin panel today
    2008-01-20 Tactics for Members
    I have more then one event store in the database using the Date format. But my MySQL query only displays the one event.

    And ideas would be great.

    I am using PHP btw.
    Ryan
    Sevierville, TN

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    GROUP BY YEAR(dt), MONTH(dt) ORDER BY dt ASC
    you are already declaring those as "Year" and "Month", but here you are using the originals?

    Code:
    SELECT DISTINCT YEAR(dt) AS 'Year', MONTH(dt) AS 'Month', DAY(dt) AS 'Day', `dt`, `description` FROM webcalendar_events_ver4 GROUP BY Year, Month ORDER BY dt ASC

  3. #3
    Join Date
    Apr 2006
    Posts
    190
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default

    I fixed the statement but its still outputting as before.
    Ryan
    Sevierville, TN

  4. #4
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Try to print out the results without the formatting to see what it is actually seeing

    Code:
    SELECT DISTINCT dt,description FROM webcalendar_events_ver4 ORDER BY dt ASC
    also be sure your php is trying to process the entire results array and not just the first one...

  5. #5
    Join Date
    Apr 2006
    Posts
    190
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default

    All I get is a bunch of 1969 nothing else LOL

    Heres my PHP code

    PHP Code:
    <?php
    $dbhost 
    '';
    $dbuser '';
    $dbpass '';
    $dbname '';

    $conn mysql_connect($dbhost$dbuser$dbpass) or die ('Error connecting to mysql');
    mysql_select_db($dbname);
        
    $result mysql_query("SELECT DISTINCT YEAR(dt) AS 'Year', MONTH(dt) AS 'Month', DAY(dt) AS 'Day', `dt`, `description` FROM webcalendar_events_ver4 GROUP BY Year, Month ORDER BY dt ASC");    
            while(list(
    $Year,$Month,$Day,$dt,$description)= mysql_fetch_row($result)){
            
            echo 
    "<b>" strftime("%B %Y",strtotime($Year "-" $Month "-01")) . "</b><br>" $dt " " $description "<br>";

    ?>
    Ryan
    Sevierville, TN

  6. #6
    Join Date
    Apr 2006
    Posts
    190
    Thanks
    3
    Thanked 7 Times in 7 Posts

    Default

    Any one have anymore thoughts??
    Ryan
    Sevierville, TN

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
  •