Jump to content

Counting and sorting simple data from a MySQL query.


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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.