Reply
Sorting the displayed data.
Old 07-05-2004, 07:12 AM Sorting the displayed data.
lothop's Avatar
Extreme Talker

Posts: 229
How can I sort the information gathered from the mysql database by order of rank.

Is there a way where I can sort the database entries in phpmyadmin, or do I have to use php code?

thanks,
Lothop
lothop is offline
Reply With Quote
View Public Profile
 
When You Register, These Ads Go Away!
Old 07-05-2004, 07:25 AM db ordering
ibbo's Avatar
Super Spam Talker

Posts: 880
Location: Leeds UK
You just need to put "order by rank asc/ desc " at the end of your sql.

Ibbo
ibbo is offline
Reply With Quote
View Public Profile Visit ibbo's homepage!
 
Old 07-05-2004, 07:54 AM
lothop's Avatar
Extreme Talker

Posts: 229
Is there an automatic way todo it..
Because if a new member joins and he is out of rank.. it would anoy me ><

Fast reply! it was like, 10 minutes hehe.

Cheers,
Lothop
lothop is offline
Reply With Quote
View Public Profile
 
Old 07-05-2004, 08:05 AM
celticbrue's Avatar
Extreme Talker

Posts: 175
Location: Wiltshire, England
Hi lothop,

Glad I was able to help with your previous post .

In relation to sorting the data, a lot depends on the type of field the rank data is kept in your database table. Probably the easiest way to do this is to assign the Rank field as a TINYINT (2) with a default value of 0 (I think this happens automatically anyway). New members would have no rank and would return 0 for rank. The next level would be 1 etc. To display the highest to lowest ranks you would have to add: -

ORDER BY rank DESC

to the end of your sql query.

I think this makes sense??

Ian.
celticbrue is offline
Reply With Quote
View Public Profile
 
Old 07-06-2004, 04:53 AM
lothop's Avatar
Extreme Talker

Posts: 229
Howdy,

I'm not sure how where to place ORDER BY rank DESC.

Does it need anything added to it? eg. ) or ;

Also, where? what? and how?

$sqlquery = "SELECT username,level_id,age,bot,country,gender FROM users";
ORDER BY rank DESC
$result = mysql_query($sqlquery);
$number = mysql_num_rows($result);

? i dunno

Thanks
Lothop
lothop is offline
Reply With Quote
View Public Profile
 
Old 07-06-2004, 05:10 AM
celticbrue's Avatar
Extreme Talker

Posts: 175
Location: Wiltshire, England
Hi there lothop,

The ORDER BY forms part of the sql query: -

$sqlquery = "SELECT sername,level_id,age,bot,country,gender FROM users ORDER BY rank DESC";

You only need the DESC if you wish to start with the highest number first. If you leave this out, it will automatically place items in ascending order, provided the database fiels is an INT type field.

Regards
Ian
celticbrue is offline
Reply With Quote
View Public Profile
 
Old 07-06-2004, 01:58 PM
lothop's Avatar
Extreme Talker

Posts: 229
I*'m getting,

PHP Code:
Warningmysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/lothop/public_html/testing/test.php on line 58 
Line 58 starts.

PHP Code:
$number mysql_num_rows($result); 
And is found in

PHP Code:
$sqlquery "SELECT username,level_id,age,bot,country,gender FROM users ORDER BY rank DESC"
$result mysql_query($sqlquery); 
$number mysql_num_rows($result); 
Ill keep working on it, thanks,
Lothop
lothop is offline
Reply With Quote
View Public Profile
 
Old 07-06-2004, 07:51 PM
celticbrue's Avatar
Extreme Talker

Posts: 175
Location: Wiltshire, England
Hi again lothop,

This one caused me to scratch my head a bit, but I think I've sussed it!

We (well me actually) have set the query to end as: -

ORDER BY rank DESC

Well this won't work, because the field in the database table that deals with the rank is actually called level_id

Try this as your query: -
PHP Code:
$sqlquery "SELECT username,level_id,age,bot,country,gender FROM users ORDER BY level_id DESC"
Also, I always connect to the database using this method: -
PHP Code:
//define database variables
$host "localhost";
$user "";
$pass ="";
$dbname "mydbname";

//connect to db

$link mysql_connect($host$user$pass)
or die(
"Could not connect : " mysql_error()); 
And code my queries results like this:
PHP Code:
$result mysql_db_query($dbname$sqlquery$link) or die("Query failed : " mysql_error()); 
I hardly ever get any problems unless I've got the syntax wrong like missing out a ; somewhere and if I do, the or die statement gives me a good idea where to start looking for the problem.

Hope this helps.

Ian.
celticbrue is offline
Reply With Quote
View Public Profile
 
Old 07-07-2004, 01:20 AM
lothop's Avatar
Extreme Talker

Posts: 229
Rank, level_id...
Yeah your right.

I should have seen it

Sorry for not picking it up lol, normally I wouldn't have a problem with that.

Thanks for saving the day lol
Lothop
lothop is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Sorting the displayed data.
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.14908 seconds with 12 queries