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 didn
t succeed. Any help please?
Asked
Active
Viewed 238 times
-4
-
I`ve been tryng to make a select to obtain the latest user inserted and then insert the new one with the key of the previous one +1 – Gonzalo Mejías Moreno Jul 09 '13 at 07:29
1 Answers
0
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

Milad.Nozari
- 2,243
- 3
- 26
- 47