Skip to main content
March 20, 2009
Question

Assigning a Record Number/Ticket number

  • March 20, 2009
  • 1 reply
  • 552 views
Hello ,

I am developing a web application.I am trying to build a functionality where user will be able to insert a new record in a table in backend MySql DB.When inserting a new ticket/record, I want the system to assign a record number/ticket number which will be unique to that particular ticket.I am trying to concatenate the company id of the user and the Id( Index) column, so that I get a unique ticket number.The problem is that the Id is generated when the record is inserted, so I cannot reference it in my insert query.Is there a way I can get my way around it and generate a unique ticket number of the format ABC12 ( ABC: Company_Id and 12: picked from ID column as of now.)?

This topic has been closed for replies.

1 reply

Inspiring
March 20, 2009
abhidev wrote:
> The problem is that the Id is generated when the
> record is inserted, so I cannot reference it in my insert query.

You can run mysql_insert_id() immediately after the insert query to get
the ID. Then use an update query to add the ticket number.

http://docs.php.net/manual/en/function.mysql-insert-id.php

--
David Powers
Adobe Community Expert, Dreamweaver
http://foundationphp.com
March 23, 2009
Thanks a lot David!!!

Its working perfectly fine.