//ดึงไอดีล่าสุดที่เพิ่งเพิ่มเข้าไป//
$id = mysql_insert_id();
//ทำรหัส5หลัก//
$lastid = sprintf("%05d",$id);
//ระบุเพศ//
if($_POST[gender]==ชาย){
$gender = "A";
}
if($_POST[gender]==หญิง){
$gender = "B";
}
$newid = $gender.$lastid;
$customer = "update member set username = '$newid' where id = '$id' ";
$query = mysql_db_query($dbname,$customer);
Date :
2011-06-09 15:56:49
By :
zandztormz
No. 5
Guest
Code (PHP)
$sql="insert into table_user(user_id,fname,lname) values((SELECT
case when max(substr(a.user_id,2,length(a.user_id)-1)) is null
then concat('A',lpad('1',5,'0'))
else concat('A',lpad(max(substr(a.user_id,2,length(a.user_id)-1))+1,5,'0'))
end
from table_user as a where a.user_id like 'A%'),'$fname','$lname')";