Jump to content

Top 10 database table


shorty3

Recommended Posts

Right Ive Made A Top 10 Racers Table But Instead of just having the list of top 10 races i want the number 1-10 example 1# - Username and so on????? This Is My Current Code

<table width="275" border="1" align="center" cellpadding="2" cellspacing="0" bordercolor="#000000" class=thinline>

        <tr> 

          <td height="20" align="center" background="includes/grad.jpg">Top 10 Street Races</td>

        </tr>

        <tr> 

          <td height="20" align="center" background="includes/gradgrey.jpg">Username</td>
        </tr>

        <?php

$tsel2 = mysql_query("SELECT * FROM `user_info` order by `races` desc limit 10");

$tsel2 = mysql_query("SELECT * FROM `users`  where `userlevel`='0'");

while ($top2 = mysql_fetch_array($tsel2)) {

	print "<tr><td height='20'><a href=$GAME_SELF?p=view&view=$top2[username]>$top2[username]</a></td></tr>";

}

?>

</table>

Link to comment
https://forums.phpfreaks.com/topic/200098-top-10-database-table/
Share on other sites

in order to get a good answer, you really need to describe the problems you are having. You have stated what you are "trying" to do, and assuming something is going wrong, you never indicate what exactly is happening. A quick look at your code showed this:

$tsel2 = mysql_query("SELECT * FROM `user_info` order by `races` desc limit 10");

$tsel2 = mysql_query("SELECT * FROM `users`  where `userlevel`='0'");

 

assuming that the first query is doing what you want (which is to get the top 10 users by races) you are overwriting the original query result with a new one (the select * where userlevel=0 one). Now tsel2 has the query results where the userlevel is 0. perhaps you mean these two variables to be separate

$tsel2 = mysql_query("SELECT * FROM `user_info` order by `races` desc limit 10");

$tsel3 = mysql_query("SELECT * FROM `users`  where `userlevel`='0'");//note there are two variables now
        // they are $tsel2, defined 3 lines above, AND $tsel3 defined 1 line above

 

 

to really fix your problem though, we need way more information. For example, what is happening? blank page? are there errors? if so, what are the exact error messages? If you have a blank page, there may still be errors, but they may not be reported if error reporting is off. to turn it on put

error_reporting(E_ALL);
ini_set("display_errors", 1);

 

at the very top of your page

The code works BUT This is what i want

 

instead of

(this is in a table btw)

top 10 races

username

 

username

username

username

username

username

username

username

username

username

username

 

This is what i want

 

top 10 races

username

 

1# username

2# username

3# username

4# username

5# username

6# username

7# username

8# username

9# username

10# username

 

 

But as the top 10 are changing all the time i dont understand how to had 1-10 before each username

you just want numbers in front of the usernames that are output by the query? in that case the fix is very simple

 

you just need a counter variable, and increment it (add 1 to it) every pass of the loop. so instead of

while ($top2 = mysql_fetch_array($tsel2)) {

	print "<tr><td height='20'><a href=$GAME_SELF?p=view&view=$top2[username]>$top2[username]</a></td></tr>";

}

 

you could put

$counter = 1;//out counter variable
while ($top2 = mysql_fetch_array($tsel2)) {

	print "#$i <tr><td height='20'><a href=$GAME_SELF?p=view&view=$top2[username]>$top2[username]</a></td></tr>";//note the change I made after the first "
                $counter++;//increment the counter

}

lol i had to tweak it

 

<?php $counter = 1;//out counter variable
while ($top2 = mysql_fetch_array($tsel2)) {
print "<tr><td height='20'>[b]#$counter [/b] <a href=$GAME_SELF?p=view&view=$top2[username]>$top2[username]</a></td></tr>";//note the change I made after the first "                
$counter++;//increment the counter	} ?>

 

But Thanks for the help couldnt of dne it without you :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.