Jump to content
xisto Community
Sign in to follow this  
alexviii

How To Group Mysql Results In A List

Recommended Posts

Ok so I have an array that I would like to group by date. When I use the group by in a mysql query it only shows one record with that value. However I want to show all the records grouped by date. This is what I have so far.

$completedprojectsresults=mysql_query("SELECT request_tbl.*, DATE_FORMAT(SubmittalDate, '%b %d, %Y') cdate ,   s.* FROM   request_tbl , site_tbl AS s WHERE request_tbl.Site_ID = s.Site_ID AND request_tbl.Date_Completed >= STR_TO_DATE('$from', '%m-%d-%Y') AND request_tbl.Date_Completed <= STR_TO_DATE('$to', '%m-%d-%Y') Group BY request_tbl.Request_ID ORDER BY cdate, s.FullSiteName");	 while($cprow=mysql_fetch_assoc($completedprojectsresults)){ echo "<dl>"; echo "Completed on  "; echo $cprow['cdate']; echo "<li>"; echo $cprow['SiteLookup']; echo "</li></dl>"; }
10x

Share this post


Link to post
Share on other sites

Why don't you put everything into an array? Actually....You could choose some random date before the while loop and assign it to a variable, say $date. At the beginning of the loop, check if the date of the next project is the same as $date. If it is, just display the project name. If it isn't, display the new date and change $date to the new date.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.