View Full Version : Complex: Ordering By Rank
As5a5sIn5
08-18-2005, 04:20 AM
Okay, I'm making a simple script that lists all the members of my site. The problem is I want to order them by rank.. but obviously SQL can't figure out which ranks are higher and which are lower :rolleyes:
So what I am asking is what is the best way to make PHP order the members by rank.. I was thinking of putting the user and rank into an array and somehow putting the ranks place (number) and then sorting by that number.. but im not quite sure how.. All i need is what exactly i have to do with the arrays.
Examples Help
Thanks in Advance
As5a5sIn5
mindlessLemming
08-18-2005, 06:07 AM
SELECT * FROM users ORDER BY rank
What's wrong with that?
For starters, your 'ranking' system should be number based anyway, as should all permissions systems. If the ranks match a 'name' (eg: a CF Nut has 1000 posts) the association between that rank and the title attached to the rank should be handled by a second table.
If your ranks aren't numbers (eg: 1 is basic, 10 is full admin), then you have an application design fault to correct, not an SQL short fall to overcome ;)
As5a5sIn5
08-18-2005, 06:30 AM
hmm.. ok.. i guess i just got overwhelmed when i couldnt figure it out.. Ill jus make a second table that holds ranks and there numbers ... but is there a SQL query that can say order by the ranks number but grab the rank out of a second table? Because I'd like to be able to put all the rank numbers in a second table in case I wanan change through control panel, or if that rank does not have any members with it.. so how do i grab both tables and order 1 by the others number..
Ultragames
08-18-2005, 07:34 AM
You shouldn't need another table. Set it up like this:
User Info Rank
Mike Blah 3
Tom Hello 2
Shelli Stuff 5
If you include the rank as another field in the same table, you can order the users by rank.
If for some reason you HAVE to put the ranks and user info in seperate tables, then i suggest keeping the IDs the same. So if User-X has a table ID of 3, then you look up ID 3 in the rank table. THen you can put the user ID numbers into an array, put the ranks in another array, and do an array_multisort.
If you need exact code, let me know.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.