Jump to content

Counting and sorting simple data from a MySQL query.


xxBUCKSxx

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

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.