Welcome Guest, Not a member yet? Register   Sign In
Insert values into eNum fields in MySql
#1

[eluser]ebrahimthex[/eluser]
Need a example DB type ENUM in MySql.
I insert manually in mysql..->

size ENUM( '30', '31', '32', '33', '34', '35', '36' ) NULL

How to insert, View & Delete... Using PHP Codeigniter or core...

I'm Doing eCommerce Type site about cloth.
#2

[eluser]TheFuzzy0ne[/eluser]
Welcome to the CodeIgniter forums!

Please could you be more specific? What values do you need in the column? I would suggest that you consider mapping out your values to another table. ENUM fields can be a pain in the butt to work with. http://komlenic.com/244/8-reasons-why-my...e-is-evil/
#3

[eluser]ebrahimthex[/eluser]
I'm create manually in mysql..->

size ENUM( ‘30’, ‘31’, ‘32’, ‘33’, ‘34’, ‘35’, ‘36’ ) NULL

now How to Select, View as a <input type="checkbox" value=" "/> using foreach loop
and want to insert some value like 31,33 and 36 size in this-DB.

I want to use a eCommerce Type site about cloth.
#4

[eluser]TheFuzzy0ne[/eluser]
That's one of the reasons it's a pain in the butt. You will have to duplicate that and put it into your model as an array, and then build your dropdown from that.

Alternatively you can do this, (which I don't think is portable):
Code:
function enum_dropdown($table, $column)
{
    $row = $this->db->query("SELECT COLUMN_TYPE FROM INFORMATION_SCHEMA.COLUMNS
        WHERE TABLE_NAME = ? AND COLUMN_NAME = ?", array($table, $column))->row_array();

    $arr = array();

    foreach (explode(',', str_replace("'", '', substr($row['COLUMN_TYPE'], 5, (strlen($row['COLUMN_TYPE']) - 6)))) as $val)
    {
        $arr[$val] = $val;
    }

    return $arr;
}

That should return an array which can be used with form_dropdown().

If you stored your values in a separate table:
Code:
function get_dropdown($table, $col)
{
    $res = $this->db
        ->select('id, '.$col)
        ->get($table)
        ->row_array();

    $arr = array();

    foreach ($res as $row)
    {
        $arr[$row['id'] = $val;
    }

    return $arr;
}

Much easier to read and understand!

Hope this helps.
#5

[eluser]ebrahimthex[/eluser]
Thank you Bro
http://russelstore.mastersite.info




Theme © iAndrew 2016 - Forum software by © MyBB