Reputation: 9221
<?php
$result = mysql_query("SELECT * FROM articles WHERE tag='sports'");
$strss=$strss+1;
while ($row = mysql_fetch_array($result))
{
echo '<li id="nav'.$strss.'"><a href="#" >'.$row['title'].'</li>';
}
?>
Why can't I set numbers automatically? the number always is 1
Upvotes: 0
Views: 75
Reputation: 21553
You need to move your counter inside the while loop like the following:
<?php
$result = mysql_query("SELECT * FROM articles WHERE tag='sports'");
$strss=1;
while ($row = mysql_fetch_array($result))
{
echo '<li id="nav'.$strss.'"><a href="#" >'.$row['title'].'</li>';
$strss++;
}
?>
Upvotes: 6