|
 |
|
สอบถามการรันนัมเบอร์เมื่อเปลี่ยนเดือนแล้วเริ่มนับ 1 ใหม่ครับ |
|
 |
|
|
 |
 |
|
เลขที่รันนัมเบอร์ พอกดรีเฟรซแล้วมันก็นับไปเรื่อยๆอ่ะครับ

ใช้แบบจากตัวอย่างนี้ครับ พอก็รีเฟรซแล้วค่ามัน+1 ยังไม่ทันบันทึก
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com Tutorial</title>
</head>
<body>
<?
//*** Connect to Database **//
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
$strNextSeq = "";
//*** Check Year ***//
$strSQL = "SELECT * FROM prefix WHERE 1 ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$objResult = mysql_fetch_array($objQuery);
//*** Check val = year,month now ***//
if($objResult["val"] == date("Y")."-".date("m"))
{
$Seq = substr("00000".$objResult["seq"],-5,5); //*** Replace Zero Fill ***//
$strNextSeq = $objResult["val"]."-".$Seq;
//*** Update Next Seq ***//
$strSQL = "UPDATE prefix SET seq= seq+1 ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
}
else //*** Check val != year,month now ***//
{
$Seq = substr("000001",-5,5); //*** Replace Zero Fill ***//
$strNextSeq = date("Y")."-".date("m")."-".$Seq;
//*** Update New Seq ***//
$strSQL = "UPDATE prefix SET val = '".date("Y")."-".date("m")."' , seq = '1' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
}
echo $strNextSeq;
mysql_close($objConnect);
?>
</body>
</html>
จะทำยังไงเมื่อกดรีเฟรซแล้วเลขมันไปเปลี่ยนตาม เพราะบางที่ยังไม่ได้กรอกข้อมูล แล้วกดรีเฟรซ มันก็กลายเป็นไปขึ้นเลขที่ใหม่
แล้วเลขที่นั้นก็จะหายไป เช่น 055 พอก็รีเฟรซมันก็จะเป็น 056
ขอบคุณครับ
Tag : PHP, HTML/CSS, JavaScript

|
ประวัติการแก้ไข 2013-06-25 16:23:00
|
 |
 |
 |
 |
Date :
2013-06-25 11:52:44 |
By :
ruud |
View :
2448 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมว่า กด refrech แล้ว count seq จะ +1
แนะนำให้อัพเดทหลังการบันทึกข้อมูลจะถูกต้องกว่าครับ
|
 |
 |
 |
 |
Date :
2013-06-25 12:43:08 |
By :
Ex-[S]i[L]e[N]t |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมว่าลองแบบนี้ดีไหม
1. เก็บ ID แบบนี้ก็ได้ ถูกแล้ว
2. ต้องเพิ่มฟิวส์ Item ขึ้นมาเก็บอีกที คือ เอา Code 3 ตัวท้าย มาเป็น Item
3. จากนั้น ก็เช็ค เดือนนั้นๆ ว่า Item ถึงไหนก็บวก 1 ต่อไปเรื่อยๆ ถ้าขึ้นเดือนใหม่ เราก็ ตัด Item มาเริ่มใหม่ (เอา item ไปต่อ ID 3 ตัวท้าย)
อย่าลืม เอาวันที่มาเช็ด + item ด้วย
พอเห็นภาพหรือ ยังครับ
select count item form 'table' where id like 'IT56/07/%'
ถ้ามีค่า
ก็เพิ่มค่า 1 ให้กับ ค่า MAX ถ้าไม่ ก็ ยัด 001 ให้ item เลย
IT56/06/001
IT56/06/002
IT56/06/003
IT56/06/004
IT56/07/001
IT56/07/002
IT56/07/003
IT56/07/004
IT56/08/001
IT ==fix
56==ปี
/==fix
06==เดือน
/==fix
001==item
Code เป็นแค่แนวทางครับ
ลองดูนะ เผื่อ
|
 |
 |
 |
 |
Date :
2013-06-25 17:43:20 |
By :
SN |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|