Forum Moderators: coopster

Message Too Old, No Replies

Understanding PHP unique property?

Understanding PHP unique property

         

BlackRaven

10:58 pm on Jan 3, 2005 (gmt 0)

10+ Year Member



hi,
i got 3 databases and some tables within them. The thing is i am trying to put an item number for each of my items, i thought i could do this with the unique field property, but the unique key only works for a database rite? How would i get a unique number with respect to the all three databases. Thank You

storevalley

11:44 pm on Jan 3, 2005 (gmt 0)

10+ Year Member



A unique key would be unique within a table, not a database. One of your tables needs to carry item information ... just use a unique key called "id" or similar in this.

Sounds like a quick session with some relational database tutorials [google.co.uk] would help clear the fog for you ...

coopster

12:51 am on Jan 4, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You could always keep a unique number in a text file or database table which you would lock and update on every new entry. Don't forget to update and unlock it, of course.

The bigger question is "why are you keeping a unique item number across 3 different databases?" As storevalley alluded, you may want to review relation and normalization.

BlackRaven

9:29 am on Jan 4, 2005 (gmt 0)

10+ Year Member



i am in the early stage of devoloping a classified, since my databases is divided to the various Houshold categorises (home appliance, furniture and lighting) i thought it would be easier to have a unique value for each of the items...something like eb@y item number.

storevalley

10:56 am on Jan 4, 2005 (gmt 0)

10+ Year Member



i thought it would be easier to have a unique value for each of the items...something like eb@y item number

Just prepend the ID with a fixed length category identifier. An example ...

An item could be numbered 12345678 where 1234 means (e.g.) "lighting", and 5678 is a unique ID (automatically generated) for the item.

When the item number is passed to your script, remove the first 4 digits and use them to work out which table to query. Then use the rest of the number as the item ID.

storevalley

11:07 am on Jan 4, 2005 (gmt 0)

10+ Year Member



Alternatively, you could just have an item table with a one or more category fields, of course ...

BlackRaven

3:49 pm on Jan 4, 2005 (gmt 0)

10+ Year Member



thanks guys, got it working now