Today a customer wants to generate 400 phone numbers in batches. The starting position is 10000. At the beginning, I directly generated numbers such as 10004. However, the merchants did not like this number, so they said that the filtering number ends in 4. Let me think about it. This can be achieved by using substr($str,-1)==4. See the code below.
代码如下 | 复制代码 |
include("cn.php"); //数据库连接类,这里不说了自己去找找吧。 $Db = new Db(); $sql ="select * from 表名 where isnew=1"; $query = $Db->query( $sql ); $rs = $Db->fetch( $query ,0); $i=10000; foreach( $rs as $v => $vv ) { if( substr($i,-1)==4 ) { $i++; } $sql ="update 表名 set txtiphone= '$i' where id=".$vv['id']; if( $Db->query( $sql ) ) { $i++; } } echo '批量更新完成'; |
About the substr() function
substr(<em>string</em>,<em>start</em>,<em>length</em>)
Parameters | Description |
---|
参数 | 描述 |
---|---|
string | 必需。规定要返回其中一部分的字符串。 |
start |
必需。规定在字符串的何处开始。
|
length |
可选。规定要返回的字符串长度。默认是直到字符串的结尾。
|
Optional. Specifies the length of the string to be returned. The default is until the end of the string.
http://www.bkjia.com/PHPjc/632231.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632231.htmlTechArticleToday a customer wanted to generate 400 phone calls in batches. The starting position was No. 10000. When I started to generate it directly, something like this appeared. But businessmen don’t like the number 10004, so the filtering mantissa is...