Current location: Hot Scripts Forums » Programming Languages » PHP » repeating....


repeating....

Reply
  #1 (permalink)  
Old 11-09-04, 04:36 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
repeating....

I want to display a users rank so I use the following:

Code:
<? 
while($row = mysql_fetch_array($results)) { 

for ($i = 1; $i <= $numrows; $i++) { 

$user = $row['username']; 
$points = $row['points']; 

echo "<tr><td>$i</td><td>$user</td><td>$points</td></tr>\n"; 
} 
} 

?>

The rank works fine but if there are 3 users then it will repeat itself 3 times

I tried putting the $i part before the while but that just gave everybody a rank of 1! any help??
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #2 (permalink)  
Old 11-09-04, 07:10 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
remove the whole for loop .. you don't need it:
PHP Code:

while($row mysql_fetch_array($results)) { 

   
$user $row['username']; 
   
$points $row['points']; 

   echo 
"<tr><td>$user</td><td>$points</td></tr>\n"

__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]

Last edited by NeverMind; 11-09-04 at 07:21 PM.
Reply With Quote
  #3 (permalink)  
Old 11-10-04, 05:56 AM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
no I need the $i thats the whole point because it determines what position they are in
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #4 (permalink)  
Old 11-10-04, 06:04 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
PHP Code:

$i 1;

while(
$row mysql_fetch_array($results)) {
   
$user $row['username'];
   
$points $row['points'];

   echo 
"<tr><td>$i</td><td>$user</td><td>$points</td></tr>\n";
   
$i++;

__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #5 (permalink)  
Old 11-10-04, 01:20 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
thanks works like a charm, should have thought of that
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #6 (permalink)  
Old 11-10-04, 03:43 PM
Eclipse's Avatar
Eclipse Eclipse is offline
Coding Addict
 
Join Date: May 2004
Location: Long Island, New York
Posts: 356
Thanks: 0
Thanked 0 Times in 0 Posts
I've been there....
Reply With Quote
  #7 (permalink)  
Old 11-10-04, 04:49 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
been where?
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #8 (permalink)  
Old 11-10-04, 04:54 PM
Eclipse's Avatar
Eclipse Eclipse is offline
Coding Addict
 
Join Date: May 2004
Location: Long Island, New York
Posts: 356
Thanks: 0
Thanked 0 Times in 0 Posts
..::whoosh::... nvm....
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Repeating MySQL records in a mail script watix PHP 2 07-22-03 05:25 PM


All times are GMT -5. The time now is 05:13 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.