mikeysites Posted August 1, 2009 Share Posted August 1, 2009 Hi all, Does anyone know how I can take a data table add all like entries & sort them by date? Output is quantity - title - size - date I need to add all quantity with matching size & title then sort by date, I can do the sort but having issues with the adding. I need it to print out a master detail of orders but dont want them to have to count how many of each. So the print should show something like, 29 baked ziti large 09/29/2009 15 baked ziti small 09/29/2009 2 baked ziti medium 09/29/2009 I dont have code to post as I am stuck on how to add them based on the size. Any help would be awesome, I hope my need is clear from what I wrote. Thanx Mike Quote Link to comment https://forums.phpfreaks.com/topic/168418-a-little-help-sorting/ Share on other sites More sharing options...
gevans Posted August 1, 2009 Share Posted August 1, 2009 Are you getting the data from a database? Quote Link to comment https://forums.phpfreaks.com/topic/168418-a-little-help-sorting/#findComment-888407 Share on other sites More sharing options...
mikeysites Posted August 1, 2009 Author Share Posted August 1, 2009 Yes sorry the data is coming from a mysql data source. Quote Link to comment https://forums.phpfreaks.com/topic/168418-a-little-help-sorting/#findComment-888408 Share on other sites More sharing options...
.josh Posted August 1, 2009 Share Posted August 1, 2009 select sum(quantity) as total from table where title='...' and size='...' order by date desc may possibly need a group by in there. Quote Link to comment https://forums.phpfreaks.com/topic/168418-a-little-help-sorting/#findComment-888409 Share on other sites More sharing options...
gevans Posted August 1, 2009 Share Posted August 1, 2009 this should work; SELECT SUM(`quantity`) AS total_quantity, `title`, `size`, `date` FROM `your-table` GROUP BY `title`, `size` ORDER BY `data` DESC; You just need to substitute `your-table` for your table name Quote Link to comment https://forums.phpfreaks.com/topic/168418-a-little-help-sorting/#findComment-888410 Share on other sites More sharing options...
mikeysites Posted August 1, 2009 Author Share Posted August 1, 2009 Thanks much I will try these & let you know how it goes. Quote Link to comment https://forums.phpfreaks.com/topic/168418-a-little-help-sorting/#findComment-888411 Share on other sites More sharing options...
.josh Posted August 1, 2009 Share Posted August 1, 2009 use gevan's. it's the same principle as mine but he filled in the blanks Quote Link to comment https://forums.phpfreaks.com/topic/168418-a-little-help-sorting/#findComment-888412 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.