How to get enum values |
[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])); }
[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 ){
[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 ![]()
[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; |
Welcome Guest, Not a member yet? Register Sign In |