in my project i need to add the user id with prefix like CL1,CL2,........
in this CL Is the prefix.my question is how can i do this?i mean how can i add the prefix to the id field using phpmyadmin?
or else i want to change the coding?
help me.....

Moderators: macek, egami, gesf



- Code: Select all
$sql ="SELECT user_id FROM `users` ORDER BY timestamp DESC";
$result = mysql_query($sql);
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);
if(empty($row)) {
// first record is going to insert. so give the user id
$user_id = 'CL1';
} else {
$pre_user_id = $row['user_id'];
$num_pre_user_id = substr($pre_user_id,2); // It will get the numeric part of the user_id
$user_id = (int)$num_pre_user_id + 1;
$user_id = 'CL'.$user_id;
}
// Now you will have your user_id. Just insert the new record which contains the new user_id.

Users browsing this forum: No registered users and 2 guests