0

I'm making a website using php and mysql and I want to create an auto increment ID for a table like this:

cl.001 , cl.002, dl.001 , dl.002 ... dl.010

The prefix is generated by a php function. I thought of this solution but I couldn't make it work:

$query='insert into table(reference) values (' . prefix() . ');'

I made an auto increment id (int), then a trigger :

TRIGGER `referenceTrig` AFTER INSERT ON `individu` 
FOR EACH ROW UPDATE individu SET REFERENCE = CONCAT(REFERENCE,NEW.id) where id=NEW.id

But this also didn't work, I also thought of and 'instead of' trigger but it doesn't exist in mysql.

Kevin
  • 41,694
  • 12
  • 53
  • 70
Amine Al
  • 77
  • 2
  • 11
  • Every newbie asks this question. You do not want to do this. – Strawberry Aug 11 '14 at 10:55
  • 1
    Depending on the database engine you're using, MySQL can do this automagically for you if you set a composite primary key; but it's rarely sensible to do so – Mark Baker Aug 11 '14 at 10:57
  • You might wanna check this link for the answer. http://stackoverflow.com/questions/17893988/how-to-make-mysql-table-primary-key-auto-increment-with-some-prefix – Htennek Nitram Anilro Apr 12 '15 at 10:26

0 Answers0