CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.

YesSoftware Forums -> CodeCharge Studio -> PHP

 Sort order of grid

Print topic Send  topic

Author Message

Posts: 27
Posted: 06/02/2015, 11:13 AM

I'm trying to make a grid where the sort order is based on the number of times a value appears in the database table.

Let me explain: users can add records to the database. Each record that they add contains the username of the submitter. Now I want to show the usernames sorted by how many records they submitted, like a top 10 list of submitters. That is:

user32 submitted 122 records
user55 submitted 109 records
user21 submitted 98 records etc....

I understand that I need to group the list by username, but how do I make the usernames appear in that order and also include the number of records each of them submitted?

Seems like it should be simple, but I'm unable to figure it out.
View profile  Send private message

Posts: 727
Posted: 06/02/2015, 11:25 AM

Try making a view or temp table that is already grouped by user and then do a sort on that.
View profile  Send private message

Posts: 27
Posted: 06/04/2015, 9:26 AM

Thanks for the reply. It's a little too unspecific for me to understand.
View profile  Send private message

Posts: 727
Posted: 06/04/2015, 10:24 PM

The group will always be automatically sorted so, to get them sorted by the number of records you will have to create either a temp table or a view.
So, lets say you are going to use a view. Select into the view something like "select count(id) as cnt from yourtable group by user."
Then you can select into your grid the view records and sort by 'cnt' descending.
View profile  Send private message

Posts: 638
Posted: 06/05/2015, 5:54 AM

I can't post it for some reason so I pm'ed you with it.

It probably looks like an attempt at injection :)
Central Coast, NSW, Australia.

View profile  Send private message

Posts: 27
Posted: 06/07/2015, 4:00 AM

Thank you for the replies, here and in private. I haven't had a chance to try any of it yet, but I will. I'm sure the solution is there.
View profile  Send private message

Add new topic Subscribe to topic   

These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit

Internet Database

Visually create Web enabled database applications in minutes.

Home   |    Search   |    Members   |    Register   |    Login

Powered by UltraApps Forum created with CodeCharge Studio
Copyright 2003-2004 by  and YesSoftware, Inc.