簡體   English   中英

PHP在while循環中添加+1

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM