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..

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.

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..

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;
?>

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)
			
			?>

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

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.. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.