Load the helper:
$this->load->helper(‘database’);
Call the function:
$enums = field_enums(‘table_name’, ‘field_name’);
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
if ( ! function_exists('field_enums'))
{
function field_enums($table = '', $field = '')
{
$enums = array();
if ($table == '' || $field == '') return $enums;
$CI =& get_instance();
preg_match_all("/'(.*?)'/", $CI->db->query("SHOW COLUMNS FROM {$table} LIKE '{$field}'")->row()->Type, $matches);
foreach ($matches[1] as $key => $value) {
$enums[$value] = $value;
}
return $enums;
}
}
/* End of file database_helper.php */
/* Location: ./application/helpers/database_helper.php */
Happy coding 🙂
Thanks!!!
It works just amazing!
Thank’s a lot, I need this script on my projects. I have try this and works perfect
Thank you very much, it’s perfect!