Jump to content

Add a rank sequence to array


spanster90

Recommended Posts

Consider the following code;

 

<div class="blockrow">
<table cellpadding="10" align="center" border="0">
<tr>
<td>
<center>
<font size=6>Donation Hall of Fame</font><br><br>
<font size=2><b>Anonymous Donations are not Counted</b></font><br><br>
<font size=3><a href="/donate">Get on This List</a></font>
<br>
<br>
<?php

//database connection
$connectdb = mysql_connect ("localhost", "user", "pass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("thatsact_donations");

//query setup
$sql = "SELECT * FROM totals ORDER BY donation_total DESC LIMIT 100";
$result = mysql_query($sql) or die(mysql_error());

//initialize container
$container = array();

//get entries from db
while ($get = mysql_fetch_assoc($result)){
if(!$get[userid]=="0")
{
$username = "<b><a style=\"color:#00CC00\" href=/member.php/$get[userid]>$get[username]</a></b> donated <b>$$get[donation_total]</b> total so far!";
}
$container[] = "<font size=3>$username</font>";
}

//combine collected entries
$output = implode("<br /><hr>",$container);

//print

echo $output;

mysql_close($connectdb);

?>
</center>
</td>
</tr>
</table>
</div>

 

I would like to add a rank number to the container starting with one and going 23456 as each piece is echoed. How might I do this because I am very new to php.

 

Example: 1. Username donated $5......

2. Username donated $4........

3. Username donated $3.......

 

Thanks in advance.

Link to comment
Share on other sites

Hmmm the ordered list option doesn't seem to work. It doesn't show anything.  :shrug:

 

This is what I am trying;

 

while ($get = mysql_fetch_assoc($result)){
if(!$get[userid]=="0")
{
$username = "<ol><li><b><a style=\"color:#00CC00\" href=/member.php/$get[userid]>$get[username]</a></b> donated <b>$$get[donation_total]</b> total so far!</li></ol>";
}
$container[] = "<font size=3>$username</font>";
}

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.