gpt4 book ai didi

php - 自动添加新的最后一个号码mysql

转载 作者:可可西里 更新时间:2023-11-01 06:44:47 25 4
gpt4 key购买 nike

我在表格的一列中有这个 ID 号,

0907003
0907004
0907005

1008005
1008006
1008007

1009001
1009002
1009003

当我添加 1009 的新值时,它会添加 004 的最后三个数字,因为最后一个数字以 1009 开头(10- 09) 是 003

或者如果我添加 1008 的新值,它将添加 008
的最后三个数字因为最后一个以 1008 开头的数字 (10-08) 是 007

或者如果我添加 0907 的新值,它将添加 006
的最后三个数字因为最后一个以 0907 开头的数字 (09-07) 是 007

如何做到这一点?

非常感谢!

$front_id = $this->input->post('gameid'); //09
$middle_id = $this->input->post('netid'); //07

//$last_id will be generate automatically by sql

$forID = $front_id.$middle_id;

$sql = "INSERT INTO table ('colum') VALUES (".$forID.")"

最佳答案

你必须手动插入新的id

    $max_of_letsay1009 = mysql_result(mysql_query("select MAX(id) from table where id like '1009%'"),0);

// get the last 3 digits
$new_number = (int)substr($max_of_letsay1009,-3) + 1;

或者你也可以试试这个:

    $new_id_of_letsay1009 = mysql_result(mysql_query("select MAX(id)+1 from table where id like '1009%'"),0);

这只是我的想法,还没有经过测试也没有查错

关于php - 自动添加新的最后一个号码mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29765609/

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