getting at field "sets" from MySQL field using php

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
jonpaulduvall
Forum Newbie
Posts: 2
Joined: Wed Jun 05, 2002 8:02 am

getting at field "sets" from MySQL field using php

Post by jonpaulduvall »

[I posted this in the PHP forum as well, but since its also about MySQL i thought i would put it in here too. Sorry to clutter up two forums.]

I am creating a generic include php script which selects a db and table, grabs all the table's fields and their names, lengths, types, and flags, and shoves them into a two-dimensional array. I then use this array to set up a form, and then use the types and flags values to validate the fields before shoving them into my database. Straight forward, i got that figured out.

mysql_field_flags gives me a string easy enough to parse out for things, such as 'set' but I want at the values that make up the "set"...

Here is the essence of my question:

When i create a field in a MySQL table the GUI i use lets me make the TYPE = "set" and i can give it a list of values for the "set." Can php get at that list?

I would use this list to generate a pull down menu field in a form. So for instance in a field which stores a state, i have a "set" like: AZ, CA, MA, WI, WA, etc. all the two letter state postal codes. I want php to get at that list. Is this possible?

I'm new to MySQL so maybe i'm using the "set" type wrong, indeed my MySQL GUI leads me to believe that "set" is a TYPE, but php's mysql_list_fields calls it a TYPE of "string" and a FLAG of "set". Am I using the "set" type/flag correctly? Is it a way to store only specific string values in a field?

I could always hard code it, but i am trying to make a generic include script so that i can use it to generate a form for inputing data into ANY table, so getting at the value choices for a "set" field and being able to stick those in an array or something would be most helpful.

Any ideas are greatly appreciated. I am a novice php programmer, the language seems easy and straightforward, but none of my reference books have a solution for this particular delima (and maybe it's impossible). Any libraries out there that might extend php-mysql functionality that might help me get at the "set" lists?

Thanks for any help. Three cheers for open-source languages!

--Jon Paul Duvall
Post Reply