GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 25-Jan-2003, 15:14
Andrew Andrew is offline
Member
 
Join Date: May 2002
Location: Yarm, Teesside, England
Posts: 145
Andrew will become famous soon enough
Question

Arrays


Hi, I will give you the code I have first and then ask the question

PHP Code:

<?phprequire("common.kor");echo "<html><body bgcolor=\"#000000\" text=\"#ffffff\">Rankings are under construction.<br><table width=50% align=center bgcolor=\"#444444\"><tr><td bgcolor=\"#222222\">Rank</td><td bgcolor=\"#222222\">Name</td><td bgcolor=\"#222222\">Reputation</td><td bgcolor=\"#222222\">Warrant</td></tr>";open_db_connection();$sql = "SELECT uid, name, reputation, warrant FROM warrior_userdata ORDER BY reputation DESC";$rank_data=mysql_query($sql);echo mysql_error();$rank_data = mysql_fetch_array($rank_data);$i = 0;while ($i < count($rank_data)-1) { // you might have to add "-1" after "count($rank_data)"$uid=$rank_data[uid];$name=$rank_data[name];$reputation=$rank_data[reputation];$warrant=$rank_data[warrant];  echo ('<tr><td>'.($i+1).'</td><td>'.$name.' (#'.$uid.')</td><td>'.$reputation.'</td><td>'.$warrant.'</td></tr>');  $i++;}/*$i = 0;$n = count($rank_data)-1;while ($i < $n){//  echo "<br>". $i. ":". $n ." ";  echo $rank_data[$i][uid];//  echo $rank_data[$i][name];  $i++;}*//*while (list($data) = each ($rank_data)){echo("<BR>$data");}*/close_db_connection();?></table></body></html>

My database is like this picture: http://mysober.co.uk/SQL.jpg

What I want to do is create a rankings page with the person with the highest reputation ranked first and then going down the ranks with decreasing reputation.

All I seem to be able to get is the same person listed every time with the code above. Where should I as the $i in to make it display all the ranks? So far where ever i put it I get errors.

Is there a better way to do this?

Thanks,
Andrew
__________________
Andrew
  #2  
Old 25-Jan-2003, 15:45
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
$rank_data is not an array, Andrew. It's a MySQL resource link identifier (usually named $result).
  #3  
Old 26-Jan-2003, 02:50
Andrew Andrew is offline
Member
 
Join Date: May 2002
Location: Yarm, Teesside, England
Posts: 145
Andrew will become famous soon enough
Quote:
Originally posted by JdS
$rank_data is not an array, Andrew. It's a MySQL resource link identifier (usually named $result).


Thanks, I think I understand what you mean. It is sorted now. I asked the people on another website aswell and they solved my problem
__________________
Andrew
 
 

Recent GIDBlogLast Week of IA Training by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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 Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Extra null element in an array samtediou MySQL / PHP Forum 2 11-Dec-2003 11:52
arrays in c wolfgangaz C Programming Language 1 26-Oct-2003 04:52

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 01:00.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.