Pergunta

I need to create an input mask using php to insert users in a database. The input mask must be like "U00000+number". Ive been trying to do it but I didnt succeed. Any help please?

Foi útil?

Solução

I'm not sure what you wanna gain here, either Uxxxxx or U00000x. But I guess you mean the first case, so:

$userid = __what_ever__;
$prefix = "U";
for($i = 0; $i < 5 - strlen((String)$userid); $i++) {
$prefix .= '0';
}
$userid = $prefix . $userid;

and for the what ever part, first get the last row of users, and do this to the user id part(ex U00456):

$userid = substr($userid, 1);
$userid = intval($userid)++;

Although it's good practice not to assign everything to the same $userid

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top