Cách lấy mã số tự động để chèn vào csdl, với ngày + tháng + năm + mã số,truy vấn Mysql .
ta có bảng masotudong: có 1 cột: idms nvarchar(50)
<?php
include 'ketnoidata.php';
date_default_timezone_set('Asia/Ho_Chi_Minh');
$mahs=0;
$sql = "select max(convert(right(idms,4), decimal)) as max from matudong where left(idms,8) = '".date("dmY")."';";
$result = mysql_query($sql)
or die("Lỗi chọn: ".mysql_error());
while($row = mysql_fetch_array($result))
$mahs = $row["max"] + 1;
if($mahs < 10)
$mahs = date("dmY")."000".$mahs;
else if($mahs < 100)
$mahs = date("dmY")."00".$mahs;
else if($mahs < 1000)
$mahs = date("dmY")."0".$mahs;
else
$mahs = date("dmY").$mahs;
?>
<input type="text" name="txtid" value="<?php echo $mahs; ?>"/>
ta có bảng masotudong: có 1 cột: idms nvarchar(50)
<?php
include 'ketnoidata.php';
date_default_timezone_set('Asia/Ho_Chi_Minh');
$mahs=0;
$sql = "select max(convert(right(idms,4), decimal)) as max from matudong where left(idms,8) = '".date("dmY")."';";
$result = mysql_query($sql)
or die("Lỗi chọn: ".mysql_error());
while($row = mysql_fetch_array($result))
$mahs = $row["max"] + 1;
if($mahs < 10)
$mahs = date("dmY")."000".$mahs;
else if($mahs < 100)
$mahs = date("dmY")."00".$mahs;
else if($mahs < 1000)
$mahs = date("dmY")."0".$mahs;
else
$mahs = date("dmY").$mahs;
?>
<input type="text" name="txtid" value="<?php echo $mahs; ?>"/>
Không có nhận xét nào:
Đăng nhận xét