gpt4 book ai didi

php - 如何在 PHP 中从 00000 开始增加数字?

转载 作者:行者123 更新时间:2023-11-29 20:51:44 25 4
gpt4 key购买 nike

我想将数字从 00000 增加到 99999。我尝试过,但不起作用。下面是我的代码:

    $result=mysql_query("select rid from regid") or die (mysql_error("No Record Found"));
while($row=mysql_fetch_array($result))
{
extract($row);

$sub=substr("$rid",15); //It is substring 00000 coming from database.

$n2 = str_pad($sub + 1, 5, 0, STR_PAD_LEFT); // It is code line.
echo $n2;
}

最佳答案

添加增量如下

 $i = 0;
while($row=mysql_fetch_array($result))
{
extract($row);

$sub=substr("$rid",15); //It is substring 00000 coming from database.

$n2 = str_pad($sub + $i, 5, 0, STR_PAD_LEFT); // It is code line.
echo $n2;
$i++;
}

关于php - 如何在 PHP 中从 00000 开始增加数字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37983616/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com