please help me, I have a problem. If I want to insert new records into table "log" where the field of it consist of : id, no_log, requester, request_date.
Id contains with no. 1, no. 2, no. 3 etc. No_log contains with 0001, 0002, 0003, 0004 etc.
The rule for no_log is "if yesterday's log was consisted from 0001 to 0010, today's log should be started from 0001 again and for tomorrow's log with the same pattern, starting with 0001 again.
I have tried to make some script bellows, but unfortunately it's not running well like I want. Please do really have your advice for this problem. Many thanks.
<?php
include('connect.php');
$request_date = "SELECT MAX(request_date) FROM log";
$curdate = date("ymd");
if ($request_date == $curdate)
{
$query = "SELECT MAX(no_log) AS maxID FROM log ";
}
else
{
$query = "SELECT no_log AS maxID FROM log WHERE request_date < curdate()";
}
$hasil=mysql_query($query);
$data=mysql_fetch_array($hasil);
$idmax=$data['maxID'];
$nomor=$idmax++;
$no_log= sprintf("%04s",$idmax);
?>
Aucun commentaire:
Enregistrer un commentaire