2012-02-14 108 views
3

我有while循環,並在那裏有論壇帖子。我想顯示帖子數量(1,2 ..)。PHP在while循環中添加+1

讓我告訴你我的想法

while($some = mysql_fetch_array($forum_posts)){ 
echo 'Number of post is $num++'; 
} 

,並顯示像

------主題-------

------帖子-------

Text of post   1. 
Text of post   2. 
Text of post   3. 

Thanks.Sorry對於英語不好

回答

6

$ num必須初始化!

$num = 1; 
while($some = mysql_fetch_array($forum_posts)){ 
echo 'Number of post is '.($num++); 
} 
0

嘗試用:

$num = 1; 
while($some = mysql_fetch_array($forum_posts)){ 
    echo 'Number of post is ' . ($num++) . '.'; 
} 

變量必須在外面串。

1
$num = 0; 

while($some = mysql_fetch_array($forum_posts)){ 
    echo 'Number of post is '.++$num; 
}