|
 |
|
ช่วยทีคับ ทำการเพิ่มรหัสพนักงานไม่ได้อ่าาา คือผมจะทำการ select รหัสพนักงานขึ้นมา |
|
 |
|
|
 |
 |
|
Code (PHP)
<?php
$test="e0001";//รหัสพนักงานเริ่มต้น
for($i=0;$i<10;$i++){ // วนรอบ 10 รอบ
$a=substr($test,0,1);//ตัดเอาเฉพาะตัว e มา
$b=substr($test,1,4);//ตัวเอาตัวเลขที่เหลือมา 4 ตัว
$b=$b+1;//เอาตัวเลขที่ได้มา +1
$b=str_pad($test,4,"0",STR_PAD_LEFT);//เติม 0 ให้เป็นตัวเลข 4 ตัว
$c=$a.$b;
print"$c<br>";
}
?>
ผลน่าจะออกมาเป็น
e0002
e0003
e0004
e0005
e0006
e0007
e0008
e0009
e0010
e0011
ผิดพลาดประการใดก็ขออภัยด้วยนะครับ เขยนสด ยังไม่ได้ลองเลย
แต่ถ้าตรงตามความต้องการ +1 ให้ด้วยนะครับ ขอบคุณครับ
|
 |
 |
 |
 |
Date :
2009-08-08 20:59:58 |
By :
monotakari |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แก้ไขบรรทัดที่ 7 เป็น
$b=str_pad($b,4,"0",STR_PAD_LEFT);//เติม 0 ให้เป็นตัวเลข 4 ตัว
|
 |
 |
 |
 |
Date :
2009-08-08 21:01:54 |
By :
monotakari |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มันได้ ee0002 ตลอดเลยอะคับ
|
 |
 |
 |
 |
Date :
2009-08-08 23:07:03 |
By :
kenzajung |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โอ ขอโทษทีครับ ผิดพลาด
บรรทัดที่ 8 และ 9 เปลี่ยนเป็น
Code (PHP)
<?php
$test=$a.$b;
print"$test<br>";
?>
ขอโทษครับผม
|
 |
 |
 |
 |
Date :
2009-08-08 23:30:37 |
By :
monotakari |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|