Log in

View Full Version : MySQL Grouping



NXArmada
02-26-2008, 03:42 PM
Right now I have this query



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.

boogyman
02-26-2008, 03:47 PM
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?


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

NXArmada
02-26-2008, 03:51 PM
I fixed the statement but its still outputting as before.

boogyman
02-26-2008, 06:22 PM
Try to print out the results without the formatting to see what it is actually seeing



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...

NXArmada
02-26-2008, 07:38 PM
All I get is a bunch of 1969 nothing else LOL

Heres my 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>";
}
?>

NXArmada
03-03-2008, 07:32 PM
Any one have anymore thoughts??