Basically I have a PHP script that creates a div for each item in the database, but I want to have a “rank” number in each div created, i.e:
-----------------
Rank: 1 < div 1
-----------------
Rank: 2 < div 2
-----------------
Rank: 3 < div 3
-----------------
And so on..
Here’s my current code…
while($row = mysql_fetch_array($result)) {
$name = stripslashes($row['name']);
$description = stripslashes($row['description']);
$votes = stripslashes($row['votes']);
$id = ($row['id']);
$link = ($row['link']);
$rank = 0;
?>
<div class="site" id="site">
<u><center>
<strong><a href="<?php echo $link ?>" target="_blank"><?php echo $name; ?></a></strong></u>
</font></center>
<p>Rank:<?php echo $rank++ ; ?></p>
<p><b><?php echo $description; ?></b><br />
Votes:<b> <?php echo $votes; ?></b><br />
</p>
</div>
<center>
<?php
}
?>
But that doesn’t work, any help would be greatly appreciated. (Also, the div’s continue over multiple pages).
Put the
$rank = 0;outside of the loop. Otherwise it will be always 0.