webmaster1 Posted January 14, 2009 Share Posted January 14, 2009 Hi All, I have the following query to output data into a web page via PHP: SELECT date FROM tablename I want to group the results by date i.e. 14th, 15th or 16th The column 'date' is of a datetime format. Does anyone know how to do this? Link to comment https://forums.phpfreaks.com/topic/140766-solved-quick-and-simple-grouping-datetime-by-date/ Share on other sites More sharing options...
xtopolis Posted January 14, 2009 Share Posted January 14, 2009 It's probably very similar to this thread: http://www.phpfreaks.com/forums/index.php/topic,233831.0.html With just a change of selection Link to comment https://forums.phpfreaks.com/topic/140766-solved-quick-and-simple-grouping-datetime-by-date/#findComment-736802 Share on other sites More sharing options...
webmaster1 Posted January 14, 2009 Author Share Posted January 14, 2009 <html> <body> <table><tr><th>Date</th></tr> <?php include("dbinfo.php"); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); //$query="SELECT date FROM zevasce"; $query=" SELECT DATE_FORMAT(date, '%a') AS 'Day of Week', count(1) AS 'Count' FROM zevasce WHERE date >= DATE_SUB(NOW(), INTERVAL 1 MONTH) GROUP BY 1 ORDER BY DAYOFWEEK(date) "; $result=mysql_query($query); $num=mysql_num_rows($result); mysql_close(); $i=0; while ($i < $num) { $date=mysql_result($result,$i,"date"); ?> <tr><td><? echo $date; ?></td></tr> <? $i++; } ?> Hmm, thanks but I get this: Date Warning: mysql_result() [function.mysql-result]: date not found in MySQL result index 4 in /xxx Warning: mysql_result() [function.mysql-result]: date not found in MySQL result index 4 in /xxx Link to comment https://forums.phpfreaks.com/topic/140766-solved-quick-and-simple-grouping-datetime-by-date/#findComment-736809 Share on other sites More sharing options...
webmaster1 Posted January 14, 2009 Author Share Posted January 14, 2009 I just changed date to Day of Week where I'm defining the $date variable and it works. The a bunch xRtopolis!!! (just kidding about the name... ) Next quest: to populate it in a dropdown. Quest thereafter: Populate a second dropdown based on the selection. Quest thereafter: Show only the results based on the second drop down selection. Link to comment https://forums.phpfreaks.com/topic/140766-solved-quick-and-simple-grouping-datetime-by-date/#findComment-736813 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.