0

I was wondering if they is a way to auto increment an id with a mixture of letters and numbers?

lets say I have a table like

table name: items

pid   name 
1     coca cola
2     fanta

I wanted to make the pid auto increment and in it it should automatic generate letters and numbers without me having to add them myself.

If you know how this can be done please give me a clear answer or a link to somewhere, where I might find the answer.

Thank you for your time.

Jessica
  • 61
  • 8
  • http://stackoverflow.com/questions/9648253/automatically-add-letters-in-front-of-an-auto-increment-fieild – Jonnny Jul 30 '13 at 17:11
  • @Jonnny I did this `UNIQUE KEY `Fake_ID` (`Fake_ID`,`ProdID`)` will that generate a mixture of letters and numbers? – Jessica Jul 30 '13 at 17:37

1 Answers1

0

If you want do this, create a new field (e.g: fake_id) then use php's uniqid function.

  • An autoincrement field is of integer type, so adding a letter there violates the constraint.
echo_Me
  • 37,078
  • 5
  • 58
  • 78
  • I have some questions about this unique. My reason i want to make my pid a mixture of letters and numbers is so that in my url no one can guess my pid. So added this new field fix id. what will be the `type` and will this auto fill out each columns? – Jessica Jul 30 '13 at 17:21
  • as i said you can create fake_id column and use it instead of id – echo_Me Jul 30 '13 at 17:23
  • okay I created a column called fake_id but they is nothing in it, so how will this work please. – Jessica Jul 30 '13 at 17:29
  • this fake_id type is var and the index is unique and it is auto_increment. please create me if I am wrong – Jessica Jul 30 '13 at 17:30
  • you didnt see my answer ? i have give you the link to create uniquid function , and you can also use it unique by many various methods. – echo_Me Jul 30 '13 at 18:03
  • i saw your answer. so i did this `UNIQUE KEY Fake_ID (Fake_ID,pid)` – Jessica Jul 30 '13 at 18:23