Hi Reader,
I was having hard time dealing with the Auto Increment in the Database, I actually wanted to generate a ticket number using the auto generated last ID which is obviously unique on its own.
So I used one function called as mysql_insert_id(); but guys trust me this only works after insert statement has been executed and if your mysql_connect does not have any parameter then it will throw you a NULL or 1 value.
TO overcome that I used a way which is by selecting the MAX value for the Auto Increment Ticket number and then adding 1 into it, which solved my purpose. A small query is written below.
$issue = mysql_query("SELECT MAX(ticNo) FROM list");
$hi=mysql_fetch_array($issue);
$for=$hi[0]+1;
$_POST['TicNo']= $for;
Now you can easily insert the post value by manipulating as per your needs and it will work. Cheers!!!
I was having hard time dealing with the Auto Increment in the Database, I actually wanted to generate a ticket number using the auto generated last ID which is obviously unique on its own.
So I used one function called as mysql_insert_id(); but guys trust me this only works after insert statement has been executed and if your mysql_connect does not have any parameter then it will throw you a NULL or 1 value.
TO overcome that I used a way which is by selecting the MAX value for the Auto Increment Ticket number and then adding 1 into it, which solved my purpose. A small query is written below.
$issue = mysql_query("SELECT MAX(ticNo) FROM list");
$hi=mysql_fetch_array($issue);
$for=$hi[0]+1;
$_POST['TicNo']= $for;
Now you can easily insert the post value by manipulating as per your needs and it will work. Cheers!!!
Comments
Post a Comment