开发者

PHP setting numbers automatically

<?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


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++;
             }
?>


Because the increment is outside the loop.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜