2012-02-14 134 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; 
}