0

hi all...
i have a problem when my boss ask me to do something that i don't know how to do it..
i need the idea for increment ID that will count by date..
For example
today is 7/3/2012,user send request then id become AB-070312-1, user send other request at the day, then id become AB-070312-2 and so on...Tomorrow, user send request and id become AB-080312-1...
hurm..i have no idea about that..do have any idea? :?:

hope all of you have idea..

3
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by HasNor
1

I can’t understand what could be the reason for such thing. Maybe not a good understanding of what a database is. Anyhow you know what the AB part of the id AB-080312-1 is , you also know how to produce the 080312 , ( date("dmy") ) , to get the last part just query count the id’s that start from AB-080312 (the previous logic) and add one to it.

0

thanks for reply..
actually AB is department, 080812 is current date, the last part is calling running number..that means how many request created from one department for a day..do get it? sorry i don't how to explain better..

0

try this

<?php
$dept="AB";
$dateStr=date("dmy");
$rs_max=mysql_query("select max(id) as maxid from your_tbl_name where your_date_field=date(now()) and your_dept_field='$dept'");
$max_id=mysql_result($rs_max,0,"maxid")+1;
$needed_string=$dept."-".$dateStr."-".$max_id;
?>

Edited by karthik_ppts: n/a

0

Thanks for reply, i've try but not work..my code here..i have tried this but it just run the first statement event dept and date already exist.. is it my condition is problem?

<?php
			$date_req=date("d/m/Y");
			$dept = $row['dept'];
			$check="SELECT * FROM request WHERE date_request='$date_req' AND dept='$dept'";
			$rs=mysql_query($check);
			$n++;
			if (mysql_num_rows($rs) == 0) {  //if not exist
			$n='1';
			}
			else   
			$n='2'; //$n++ (increase if date and dept already exist)
			
			?>
0

erm..this actually something like count transaction for day by department and date..

0

Thank you Karthik_pranas for help..
actually yesterday i've study clearly how your given code's running, then i got it..
hurm..thank you very much..now i'm still in debung.. anyway TQVM.. :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.