![]() |
How to get enum values - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How to get enum values (/showthread.php?tid=14433) |
How to get enum values - El Forum - 01-02-2009 [eluser]Unknown[/eluser] I've just started using CI but I've ran into a problem handling enum, just wondering if anyone has any suggestions? I have some fields in the database (mysql) that are set as enum e.g. platform. Is there a function to get the values of these enum ? I had previously used code like this but I was wonder if CI had a nicer way to do it? $query="SHOW COLUMNS FROM hds_scripts LIKE 'Platform'"; $result=mysql_query($query); if(mysql_num_rows($result)>0){ $row=mysql_fetch_row($result); $options=explode("','",preg_replace("/(enum|set)\('(.+?)'\)/","\\2",$row[1])); } How to get enum values - El Forum - 02-18-2009 [eluser]Chalda Pnuzig[/eluser] I have the same problem... Have you solved it? [edit] I found this function from http://akinas.com/pages/en/blog/mysql_enum : Code: function enum_select( $table , $field ){ In CI: Code: function enum_select( $table , $field ){ How to get enum values - El Forum - 05-20-2010 [eluser]psychobob[/eluser] [quote author="Chalda Pnuzig" date="1234999201"]I have the same problem... Have you solved it? [edit] I found this function from http://akinas.com/pages/en/blog/mysql_enum : Code: function enum_select( $table , $field ){ In CI: Code: function enum_select( $table , $field ){ I adjusted your code like this: Code: function enum_select( $table , $field ) to call the function I do Code: echo form_dropdown('test', $this->db->enum_select('admins','access_level')); Hope this helps! I appreciate what you had, because that sure helped me ![]() How to get enum values - El Forum - 07-15-2010 [eluser]LiorBroshi[/eluser] Thanks...exactly what I needed ;-) Small Fix: This: Code: $row = $this->query("SHOW COLUMNS FROM ".$table." LIKE '$field'")->row()->Type; should be Code: $row = $this->db->query("SHOW COLUMNS FROM ".$table." LIKE '$field'")->row()->Type; |