4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 PHP: Getting Data Out Of An Array
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
Iyonix
WebHelper
WebHelper


Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England

PostPosted: Sat Jan 25, 2003 8:00 pm (21 years, 2 months ago) Reply with QuoteBack to Top

This is really confusing me Rolling Eyes
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
OfflineView User's ProfileFind all posts by IyonixSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Sat Jan 25, 2003 8:22 pm (21 years, 2 months ago) Reply with QuoteBack to Top

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++;
}

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Iyonix
WebHelper
WebHelper


Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England

PostPosted: Sat Jan 25, 2003 9:26 pm (21 years, 2 months ago) Reply with QuoteBack to Top

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
Quote:

1 K 1 1


The first users has uid of 1 a name of Kelvin, reputation of 100 and warrant 1000. Any ideas?

________________________________
Iyonix
OfflineView User's ProfileFind all posts by IyonixSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Sun Jan 26, 2003 8:37 am (21 years, 2 months ago) Reply with QuoteBack to Top

OK, let's not waste too much time Very Happy

Try this, and tell me the output. Then we can use the correct variable names:

Code:
print_r($rank_data);

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Iyonix
WebHelper
WebHelper


Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England

PostPosted: Sun Jan 26, 2003 9:09 am (21 years, 2 months ago) Reply with QuoteBack to Top

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
OfflineView User's ProfileFind all posts by IyonixSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Sun Jan 26, 2003 9:12 am (21 years, 2 months ago) Reply with QuoteBack to Top

Can you post it with the line breaks and indentation (use view source to find them)?

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Iyonix
WebHelper
WebHelper


Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England

PostPosted: Sun Jan 26, 2003 9:13 am (21 years, 2 months ago) Reply with QuoteBack to Top

Array
(
[0] => 5
[uid] => 5
[1] => Fegor
[name] => Fegor
[2] => 109
[reputation] => 109
[3] => 1000
[warrant] => 1000
)

________________________________
Iyonix
OfflineView User's ProfileFind all posts by IyonixSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Sun Jan 26, 2003 9:16 am (21 years, 2 months ago) Reply with QuoteBack to Top

Is that all there is? Because there should be the info for all the rows in the table...

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Iyonix
WebHelper
WebHelper


Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England

PostPosted: Sun Jan 26, 2003 9:17 am (21 years, 2 months ago) Reply with QuoteBack to Top

Daniel wrote:
Is that all there is? Because there should be the info for all the rows in the table...


Thats all there is Sad

________________________________
Iyonix
OfflineView User's ProfileFind all posts by IyonixSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Sun Jan 26, 2003 9:24 am (21 years, 2 months ago) Reply with QuoteBack to Top

Is Fegor the last or first user in the table?

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Iyonix
WebHelper
WebHelper


Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England

PostPosted: Sun Jan 26, 2003 9:26 am (21 years, 2 months ago) Reply with QuoteBack to Top

Daniel wrote:
Is Fegor the last or first user in the table?


Fegor is first if the users are ordered by reputation.

________________________________
Iyonix
OfflineView User's ProfileFind all posts by IyonixSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Sun Jan 26, 2003 9:26 am (21 years, 2 months ago) Reply with QuoteBack to Top

Actually, here's a better idea:

Code:
    while ($row = mysql_fetch_array($rank_data, MYSQL_ASSOC)) {
        print ('ID: '.$row['id'].'<br />Name: '.$row['name']);
    }

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Iyonix
WebHelper
WebHelper


Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England

PostPosted: Sun Jan 26, 2003 9:30 am (21 years, 2 months ago) Reply with QuoteBack to Top

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 Very Happy It worked Smile

Thanks,
Iyonix

________________________________
Iyonix
OfflineView User's ProfileFind all posts by IyonixSend Personal Message
Iyonix
WebHelper
WebHelper


Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England

PostPosted: Thu Jan 30, 2003 7:22 pm (21 years, 2 months ago) Reply with QuoteBack to Top

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
OfflineView User's ProfileFind all posts by IyonixSend Personal Message
Daniel
Team Member



Joined: 06 Jan 2002
Posts: 2564

PostPosted: Fri Jan 31, 2003 7:13 am (21 years, 2 months ago) Reply with QuoteBack to Top

Code:
$sql = "SELECT uid, name, reputation, warrant FROM warrior_userdata ORDER BY reputation WHERE reputation > 19";


Question

________________________________
Image
OfflineView User's ProfileFind all posts by DanielSend Personal Message
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot edit your posts in this forum.
You cannot delete your posts in this forum.
You cannot vote in polls in this forum.


Page generation time: 0.295269 seconds :: 18 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme