Author |
Message |
Iyonix
WebHelper
Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England
|
Posted:
Sat Jan 25, 2003 8:00 pm (21 years, 2 months ago) |
|
This is really confusing me
I am trying to make a rankings page for my online game that ranks the users by reputation.
Code: |
open_db_connection(); //My own connection function
$sql = "SELECT uid, name, reputation, warrant FROM warrior_userdata ORDER BY reputation";
$rank_data=mysql_query($sql);
echo mysql_error();
$rank_data = mysql_fetch_array($rank_data);
close_db_connection();
|
How do I actually get it to display all the data it has retrieved?
Thanks, |
________________________________ Iyonix |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Sat Jan 25, 2003 8:22 pm (21 years, 2 months ago) |
|
Something like this should do it:
Code: | $i = 0;
while ($i < count($rank_data)) { // you might have to add "-1" after "count($rank_data)"
echo ('Bla Bla '.$rank_data[$i]['name']);
$i++;
} |
|
________________________________
|
|
|
|
Iyonix
WebHelper
Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England
|
Posted:
Sat Jan 25, 2003 9:26 pm (21 years, 2 months ago) |
|
Daniel wrote: | Something like this should do it:
Code: | $i = 0;
while ($i < count($rank_data)) { // you might have to add "-1" after "count($rank_data)"
echo ('Bla Bla '.$rank_data[$i]['name']);
$i++;
} |
|
This returns
The first users has uid of 1 a name of Kelvin, reputation of 100 and warrant 1000. Any ideas? |
________________________________ Iyonix |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Sun Jan 26, 2003 8:37 am (21 years, 2 months ago) |
|
OK, let's not waste too much time
Try this, and tell me the output. Then we can use the correct variable names:
Code: | print_r($rank_data); |
|
________________________________
|
|
|
|
Iyonix
WebHelper
Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England
|
Posted:
Sun Jan 26, 2003 9:09 am (21 years, 2 months ago) |
|
Daniel wrote: |
Code: | print_r($rank_data); |
|
Array ( [0] => 5 [uid] => 5 [1] => Fegor [name] => Fegor [2] => 109 [reputation] => 109 [3] => 1000 [warrant] => 1000 ) |
________________________________ Iyonix |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Sun Jan 26, 2003 9:12 am (21 years, 2 months ago) |
|
Can you post it with the line breaks and indentation (use view source to find them)? |
________________________________
|
|
|
|
Iyonix
WebHelper
Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England
|
Posted:
Sun Jan 26, 2003 9:13 am (21 years, 2 months ago) |
|
Array
(
[0] => 5
[uid] => 5
[1] => Fegor
[name] => Fegor
[2] => 109
[reputation] => 109
[3] => 1000
[warrant] => 1000
) |
________________________________ Iyonix |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Sun Jan 26, 2003 9:16 am (21 years, 2 months ago) |
|
Is that all there is? Because there should be the info for all the rows in the table... |
________________________________
|
|
|
|
Iyonix
WebHelper
Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England
|
Posted:
Sun Jan 26, 2003 9:17 am (21 years, 2 months ago) |
|
Daniel wrote: | Is that all there is? Because there should be the info for all the rows in the table... |
Thats all there is |
________________________________ Iyonix |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Sun Jan 26, 2003 9:24 am (21 years, 2 months ago) |
|
Is Fegor the last or first user in the table? |
________________________________
|
|
|
|
Iyonix
WebHelper
Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England
|
Posted:
Sun Jan 26, 2003 9:26 am (21 years, 2 months ago) |
|
Daniel wrote: | Is Fegor the last or first user in the table? |
Fegor is first if the users are ordered by reputation. |
________________________________ Iyonix |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Sun Jan 26, 2003 9:26 am (21 years, 2 months ago) |
|
Actually, here's a better idea:
Code: | while ($row = mysql_fetch_array($rank_data, MYSQL_ASSOC)) {
print ('ID: '.$row['id'].'<br />Name: '.$row['name']);
} |
|
________________________________
|
|
|
|
Iyonix
WebHelper
Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England
|
Posted:
Sun Jan 26, 2003 9:30 am (21 years, 2 months ago) |
|
Daniel wrote: | Actually, here's a better idea:
Code: | while ($row = mysql_fetch_array($rank_data, MYSQL_ASSOC)) {
print ('ID: '.$row['id'].'<br />Name: '.$row['name']);
} |
|
Thank you sooo much It worked
Thanks,
Iyonix |
________________________________ Iyonix |
|
|
|
Iyonix
WebHelper
Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England
|
Posted:
Thu Jan 30, 2003 7:22 pm (21 years, 2 months ago) |
|
Sorry to be annoying and asking loads of questions, but How would I make it display only the people ranked 20 above and below the user by reputation?
Thanks in advance, |
________________________________ Iyonix |
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Fri Jan 31, 2003 7:13 am (21 years, 2 months ago) |
|
Code: | $sql = "SELECT uid, name, reputation, warrant FROM warrior_userdata ORDER BY reputation WHERE reputation > 19"; |
|
________________________________
|
|
|
|
|