|
 |
|
อยากออก ร หั ส ใ บ สั่ ง ซื้ อ โดยมีตัวหนังสือด้วย อ่ะค่้ะ |
|
 |
|
|
 |
 |
|
บทความนี้ได้เลยครับ เพียงเปลี่ยนตัวเลขข้างหน้าเป็นตัวอักษรก็ใช้ได้เลยครับ
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 now ***//
if($objResult["val"] == date("Y"))
{
$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 now ***//
{
$Seq = substr("000001",-5,5); //*** Replace Zero Fill ***//
$strNextSeq = date("Y")."-".$Seq;
//*** Update New Seq ***//
$strSQL = "UPDATE prefix SET val = '".date("Y")."' , seq = '1' ";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
}
echo $strNextSeq;
mysql_close($objConnect);
?>
</body>
</html>
Go to : PHP Auto Generate Number ตัวอย่างการทำ Auto Number แบบมี รหัส/ตัวอักษร/ปี/เดือน ข้างหน้า
|
 |
 |
 |
 |
Date :
2011-05-04 11:45:05 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แบบนี้ก็ได้ครับลองดู
Code (PHP)
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?
include "config.php";
$pname=$_POST['pname'];
////--------------------เก็บรหัสสินค้าเป็นรหัส------------------************
$sql = "SELECT a_id FROM tb_adapter ORDER BY a_id DESC LIMIT 1";
$result = mysql_query($sql);
if(mysql_num_rows($result) > 0)
{
$row = mysql_fetch_array($result);
sscanf($row[0] ,"A%d" , $id);
$id++;
$sql = "INSERT INTO tb_adapter VALUES(CONCAT('A',RIGHT(CONCAT('0000' , $id) , 4)) ,'$pname','stock')";
}
else
{
$sql = "INSERT INTO tb_adapter VALUES('A0001','$pname','stock')";
}
mysql_query($sql);
$affected_rows = mysql_affected_rows();
if ($affected_rows > 0) {
echo "<script>alert(' การทำรายการเสร็จสมบูรณ์'); window.location ='add_adapter.php';</script>";
echo "<script>alert(' ไม่สามารถทำรายการได้ครับ ');history.back();</script>";
} else {
}
mysql_close();
?>
|
 |
 |
 |
 |
Date :
2011-05-04 11:51:28 |
By :
chonburi f.c |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุง ทุกความเห็ นะค่ะ จะลองทำดูคะ่    
|
 |
 |
 |
 |
Date :
2011-05-04 12:03:21 |
By :
sajok |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
มีอีก1ตัวเลือกครับ ลองดู
Code (PHP)
$sql_max_IDemp = "SELECT max(id_emp) as max_IDemp FROM `employee`";
$query_max_IDemp = mysql_query($sql_max_IDemp) or die ("Error Query [".$sql_max_IDemp."]");
$rs = mysql_fetch_array($query_max_IDemp);
$maxes = $rs[max_IDemp];
$max_ID=substr($maxes,3);
//$max_ID = 1110;
$max_ID = $max_ID +1;
if ($max_ID<10){
$max_ID = '000'.$max_ID;
}else if ($max_ID<100){
$max_ID = '00'.$max_ID;
}else if ($max_ID<1000){
$max_ID = '0'.$max_ID;
}
$max_IDemp='SAL'.$max_ID;
|
 |
 |
 |
 |
Date :
2011-05-06 19:45:48 |
By :
HaKonNan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|