xxBUCKSxx Posted December 8, 2008 Share Posted December 8, 2008 Hi Guys!! I have been looking around but getting nowhere fast, i'm sure my problem is really easy I just can't find a starting point.... I need to sort an array ($result) with data lookin like this User_ID Page_id ------- -------- 123 63 23 63 56 63 23 42 65 63 22 42 78 63 and sort it into an array ($sort) data looking like this page_id count -------- ------ 63 5 42 2 it needs to be open ended so if more data get added say a new page_id other than 42 or 63 it will give me the count of the new page_id in the results, I dare say the solution is quite obvious, but I just can find anything to help, help me obi-wan! any help would be greatly appreciated even my c64 advanced programmers guide can't help!! Cheers Steve Bucks Quote Link to comment https://forums.phpfreaks.com/topic/136036-counting-and-sorting-simple-data-from-a-mysql-query/ Share on other sites More sharing options...
xxBUCKSxx Posted December 8, 2008 Author Share Posted December 8, 2008 Forgot to mention I am using MySQL 5 Quote Link to comment https://forums.phpfreaks.com/topic/136036-counting-and-sorting-simple-data-from-a-mysql-query/#findComment-709292 Share on other sites More sharing options...
PFMaBiSmAd Posted December 8, 2008 Share Posted December 8, 2008 This is a basic query. Reading a basic mysql book or going through a good mysql tutorial would have given you the staring point you need to be effective at doing it yourself. SELECT page_id, count(*) as count FROM your_table GROUP BY page_id Quote Link to comment https://forums.phpfreaks.com/topic/136036-counting-and-sorting-simple-data-from-a-mysql-query/#findComment-709451 Share on other sites More sharing options...
xxBUCKSxx Posted December 8, 2008 Author Share Posted December 8, 2008 Sorry, I didn't mean to offend I didn't know of the count command and didn't come across it while browsing around, thanks for the pointer. Quote Link to comment https://forums.phpfreaks.com/topic/136036-counting-and-sorting-simple-data-from-a-mysql-query/#findComment-709827 Share on other sites More sharing options...
xxBUCKSxx Posted December 8, 2008 Author Share Posted December 8, 2008 Just incase anyone is a MySQL query noob like me and needs it, I found a great tutorial with examples of counting/adding up data from queries... http://www.tizag.com/mysqlTutorial/mysqlcount.php Quote Link to comment https://forums.phpfreaks.com/topic/136036-counting-and-sorting-simple-data-from-a-mysql-query/#findComment-709841 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.