...

View Full Version : How do I increase +1 in while loop?



myfayt
11-08-2010, 01:30 PM
I am using a WHILE loop to extract data from the database. I want it to show, 1,2,3,4,5 and keep counting up every record it pulls. What do I add for the +1?


echo '<select name="fire">';
while ($runecheck = mysql_fetch_array($runecheck2))
{
$inc = $inc +1;
echo "<option value="$inc">$inc Runes</option>";
}
echo '</select>';

djm0219
11-08-2010, 01:35 PM
What you have should work but it might be clearer to do it like this:



$inc = 0;
echo '<select name="fire">';
while ($runecheck = mysql_fetch_array($runecheck2))
{
$inc++;
echo '<option value="' . $inc . '">' . $inc . ' Runes</option>';
}
echo '</select>';

myfayt
11-08-2010, 01:54 PM
Thanks! I couldn't remember the $inc++; part.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum