0
I am using the code below to test with a login system in PHP and Mysql. But the field nivel_usuario
generates a number from 0 to 2, and I would like it to generate a unique 6-digit ID containing numbers and letters (both upper and lower case)
CREATE TABLE usuarios(
usuario_id int(5) NOT NULL auto_increment,
nome varchar(50) NOT NULL default '',
sobrenome varchar(50) NOT NULL default '',
email varchar(100) NOT NULL default '',
usuario varchar(32) NOT NULL default '',
senha varchar(32) NOT NULL default '',
info text NOT NULL,
nivel_usuario enum('0','1','2') NOT NULL default '0',
data_cadastro datetime NOT NULL default '0000-00-00 00:00:00',
data_ultimo_login datetime NOT NULL default '0000-00-00 00:00:00',
ativado enum('0','1') NOT NULL default '0',
PRIMARY KEY (usuario_id)
) ENGINE = MYISAM CHARACTER SET latin1 COLLATE latin1_general_ci COMMENT = '';
Simply show the user_id field on some basis with the desired characters (for example, base 36 or 64). Probably any solution that runs away from this is doubtful, as the fact of using a character set other than just numbers is mere formatting. If you need pseudorandomness (which you also need to see if it is really necessary) you could use a multiplier factor based on a prime number, for example. But you need to see if you really need it.
– Bacco