|
![](/images/resource/spacer.gif) |
|
ต้องการรันรหัส PR2008001001 ไปเรื่อยๆๆ ครับ ต้องการเขียนโปรแกรมให้รันรหัสอัตโนมัติ โดยขึ้นต้นด้วย PR แล้วตามด้วย |
|
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
คงต้องใช้ตัวแปรเข้าช่วยอ่ะครับ ตัวแปรนี้อาจได้มาจากการ select ก่อนที่จะทำการ insert ข้อมูล
เช่นพอเรา select id ที่เป็น autoincrement มา
เราก็จะได้ค่า $id = $fetcharr['ID'];
ค่าไอดีเราออกมาเป็น 0
เราก็มากำหนดอีกทีว่า ให้มัน +1
$sql = "SELECT id From table";
$result = mysql_query($sql);
$id = $fetcharr['id'];
$id = $id +1;
เราก็เอาค่าไอดีไปแนบกับที่เราจะเก็บอีกที
$num = "PR200800100".$id;
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
30 มี.ค. 2551 20:03:43 |
By :
deawx |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ลองเอาไปปรับใช้ดูนะคับ เผื่อจะช่วยอะไรได้บ้างคับ
function Define_calculateID2($table, $feild, $default='PO'){
$cond = $default.(date("y")+43).'0';
$sql = "SELECT $feild FROM $table
WHERE $feild LIKE '$cond%'
ORDER BY $feild DESC";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
if($row[$feild] == "")
$id = $default.(date("y")+43).'0'.'001';
else{
// Q510001 <-- ผลที่ออกมาคับ
$a1 = substr($row[$feild],5,1);
$a2 = substr($row[$feild],6,1);
$a3 = substr($row[$feild],7,1);
if($a3 == 9){
$a3 = 0;
if($a2 == 9){
$a2 = 0;
$a1 ++;
}else
$a2++;
}else
$a3++;
$id = $default.(date("y")+43).'0'.$a1.$a2.$a3;
}
return $id;
}
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
31 มี.ค. 2551 11:28:26 |
By :
maruk |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
![](/images/resource/viewboard_01.gif?v=1001) |
|
|
![](/images/resource/viewboard_03.gif?v=1001) |
![](/images/resource/viewboard_04.gif?v=1001) |
|
ขอบคุณงับจะเอาเป็นนวนะ
|
![](/images/resource/blockviewtopic_01.gif?v=1001) |
![](/images/resource/blockviewtopic_02.gif?v=1001) |
![](/images/resource/blockviewtopic_03.gif?v=1001) |
![](/images/resource/blockviewtopic_04.gif?v=1001) |
Date :
2011-04-20 16:38:26 |
By :
badkung04 |
|
![](/images/resource/blockviewtopic_06.gif?v=1001) |
![](/images/resource/blockviewtopic_07.gif?v=1001) |
![](/images/resource/blockviewtopic_08.gif?v=1001) |
![](/images/resource/blockviewtopic_09.gif?v=1001) |
|
|
![](/images/resource/viewboard_06.gif?v=1001) |
![](/images/resource/viewboard_07.gif?v=1001) |
|
![](/images/resource/viewboard_08.jpg?v=1001) |
![](/images/resource/viewboard_09.gif?v=1001) |
|
|
|
![](/images/digitalocean-banner.jpg)
|
Load balance : Server 01
|