Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL 'SET' datatype and PHP

Status
Not open for further replies.

MrBelfry

IS-IT--Management
May 21, 2003
289
Hi there guys

I'm developing a php application for managing contacts. On of the fields in the db will contain title information ie 'Mr', 'Mrs', 'Dr' etc - I've used the set datatype to add a little bit of validation. Is there anyway that PHP can access the values I've entered as the set datatype or do these values need to be handcoded

MrBelfry
 
You can get MySQL to describe a set column using a query like:

SHOW COLUMNS FROM table_name LIKE 'set_column_name'

And parse the return.


However, keep in mind that unless you have a set of titles, you will have to keep changing the definition of your set when a new one comes along. This is a bad idea. In such case, I recommend using a related table to store titles.




Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks sleipnir

I would have used a related table but I was feeling lazy. There would also be very few occasions when I would need to update the set of titles - once you get past Mr, Mrs, Ms, Mr & Mrs, Dr etc there are very few left.

However as I'd have to parse the results of the query anyway it is probably best to use a related table.

Thanks

MrBelfry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top