询问有关php的摘要01 + 01 = 02 [英] ask about php summarize 01 + 01 = 02

查看:77
本文介绍了询问有关php的摘要01 + 01 = 02的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在数据库中创建一个ID

I want to make a id in database

id_user =>数据类型'varchar'

id_user => data type 'varchar'

我希望我的ID以000102等开头. 为了创建新的ID,我对所有行进行计数,计数结果将加01.

I want my id to start from 00, 01, 02, and so on. And to make new id, I count the all the rows, and the result from count will be added by 01.

示例:

$id=array(00,01,02);
$count_exist_id = $count($id)
$new_id= '00' + $count_exist_id

,我希望新ID必须为'03',并将其存储在表用户列id_user

and I hope the new id must be '03' and it will be store to database in table user column id_user

推荐答案

您可以使用INT(x) ZEROFILL在数字前加0. '1'=>'001'

You can use INT(x) ZEROFILL, to add 0 before the number. '1' => '001'

使用 INT零填充,您可以拥有AUTO_INCREMENT. ;)

With INT ZEROFILL, you have AUTO_INCREMENT. ;)

CREATE TABLE user (
   id_user INT(8) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT, 
   PRIMARY KEY(id_user)
);

如果使用UNSIGNED,则可以优化表,并节省一个BIT,以获得更大的数字.

If you use UNSIGNED, you optimize your table, and you save one BIT, to get bigger number.

请参阅:

  • What is the benefit of zerofill in MySQL?
  • How can I set autoincrement format to 0001 in MySQL?
  • What does "unsigned" in MySQL mean and when to use it?

这篇关于询问有关php的摘要01 + 01 = 02的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆