Jump to content

help with php ranking page


fintastik

Recommended Posts

I am making a php ranking page for a game i play,

 

I pull all the characters from the database and sort them by their level using:

<table width="100%">
	<tr>
		<th>Rank</th>
		<th>Name</th>
		<th>Character</th>
		<th>Level</th>
	</tr>
<?php

$data = array();

if (isset($gp_army)) {
	$data[] = $gp_army;
}

$chars = $db->query("
	SELECT g.GameID, Face, Lvl
	FROM tblGameID1 g
	WHERE g.GameID NOT LIKE 'GM%'
		AND g.GameID NOT LIKE 'GC%'
		AND Permission < 65535
		" . (isset($gp_type) ? ("AND Face = " . intval($gp_type)) : '' ) . "
	ORDER BY Lvl DESC", $data);

$i = 0;
while ($i < $maxdisp && $chars->fetch()) {
	?>
		<tr>
			<td><-- rank cell --></td>
			<td ><?= htmlspecialchars($chars->GameID) ?></td>
			<td><?= character_type($chars->Face) ?></td>
			<td><?= $chars->Lvl ?></td>

		</tr>

 

the problem I am having is, i want the rank cell in the table to go from 1-1000, but not sure exactly how to do it since the table is made on the fly.I messed around using a numbered list, but could only make it repeat #1

<tr>
			<td><ol><li></td>
			<td ><?= htmlspecialchars($chars->GameID) ?></td>
			<td><?= character_type($chars->Face) ?></td>
			<td><?= $chars->Lvl ?></td>

		</tr>

 

any help or ideas would be appreciated.

 

Thanks

 

 

Link to comment
Share on other sites

<tr>
            <td><? /*ugh short-tags*/ echo $i+1; ?></td>
            <td ><?= htmlspecialchars($chars->GameID) ?></td>
            <td><?= character_type($chars->Face) ?></td>
            <td><?= $chars->Lvl ?></td>
            
         </tr>

Link to comment
Share on other sites

That's a huge table  ;) You will not display it on a normal website I guess? Then it's no issue. If you only wish to have 1000 hits you should add LIMIT 1000 to the end of your sql command. It's unnecessary to select 50000 values if you only need 1000.

 

You should do this to count:

 

$counter = 0;
while (blabla)
{
    $counter++;
    echo $counter;
}

 

That will display the $counter value which will increase by 1 on each loop. However, you may want to correct it for equal values (there could be 10 having a score of 2538 for example).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.