[英]PHP add +1 in while loop
我有while循環,並且有論壇帖子。我想顯示帖子數量(1,2 ..)。
讓我告訴你我的想法
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.
謝謝。抱歉英語不好
$ num必須初始化!
$num = 1;
while($some = mysql_fetch_array($forum_posts)){
echo 'Number of post is '.($num++);
}
$num = 0;
while($some = mysql_fetch_array($forum_posts)){
echo 'Number of post is '.++$num;
}
試試:
$num = 1;
while($some = mysql_fetch_array($forum_posts)){
echo 'Number of post is ' . ($num++) . '.';
}
變量必須在字符串之外。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.