MySQL: Query to return enumerated types?

  Post new topicReply to topicPrintable Version
<< View previous topic View next topic >>
Share: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
#1   MySQL: Query to return enumerated types?
cnbingham
CZ Newbie
cnbingham has been a member for over 20 year's 20 Year Member
Status: Offline
Joined: Oct 25, 2004
0.00 posts per day
Posts: 13
Points: 940
   
Folks,

How might I query & display the enumerated types located in a MySQL db table so I can display them in pull-down menu in a phpnuke block?

The field is defined as:

type | enum('Published Article', 'Newsletter', 'Whitepaper') | default('Published Article')

Without examining each and every article stored in the database, is there a way to pull out the enumerations so I can display them in a drop-down?

The alternative is to create an ancillary table indexed by ID containing the text label. Now that I think about it, is that a better way to handle it because it offers easier internationalization?

Curtis



Back to top Reply with quote
#2   re: MySQL: Query to return enumerated types?
cnbingham
CZ Newbie
cnbingham has been a member for over 20 year's 20 Year Member
Status: Offline
Joined: Oct 25, 2004
0.00 posts per day
Posts: 13
Points: 940
   
Whups. Found the answer


   $result_pubs = $db->sql_query("SHOW COLUMNS FROM ".$prefix."_pcgpublications LIKE 'type'");
   // code from MySQL Manual http://dev.mysql.com/doc/mysql/en/ENUM.html
   if($db->sql_numrows($result_pubs)>0){
   $row=$db->sql_fetchrow($result_pubs);
   $pub_list=explode("','",preg_replace("/(enum|set)\('(.+?)'\)/","\\2",$row[1]));

The query returns a row that contains the name of the field in the first column and the type in the 2nd column. The perl regex parses the row to extract just the names of the enumerations.

Curtis


Back to top Reply with quote
Display posts from previous:      
Add To: Del.icio.us  Digg  Google  Spurl  Blink  Furl  Y! MyWeb  
<< View previous topic View next topic >>
Post new topicReply to topic

Jump to 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum