Welcome Guest, Not a member yet? Register   Sign In
Re-populating select from db and validate it?
#6

[eluser]The Wizard[/eluser]
i use it like this:

Code:
function dropdown_event_status( $name, $selected_id = '' )
    {

        $this->db->select('id, status_id, name');

        $this->db->from('event_status');

        $query = $this->db->get();

        $num_rows = $query->num_rows();

        if ( $num_rows <= 0)
        {
            die ('nothing returned');
        }
        else
        {

            $result_array = array();
            foreach ($query->result_array() as $row)
            {
                $temp = array( $row['status_id'] => $row['name']  );
                $result_array = array_merge( $result_array, $temp );
            }

            $this->load->helper('form');
            return form_dropdown( $name, $result_array, $selected_id );
        }

    }

    $data['values']['status_id']        = $this->model_event->dropdown_event_status( 'status_id', 'SELECTED' ); // this gives us the selected

and in the form i use:
Code:
Status ID: &lt;?= $values['status_id'] ?&gt;


1. i generate the whole dropdown from code
2. i kinda hack use it for the validation
3. more practical, much nicer
4. http://ellislab.com/forums/viewthread/103419/
check out my tutorial


Messages In This Thread
Re-populating select from db and validate it? - by El Forum - 02-01-2009, 08:16 AM
Re-populating select from db and validate it? - by El Forum - 02-01-2009, 08:52 AM
Re-populating select from db and validate it? - by El Forum - 02-01-2009, 12:49 PM
Re-populating select from db and validate it? - by El Forum - 02-01-2009, 01:55 PM
Re-populating select from db and validate it? - by El Forum - 02-01-2009, 02:08 PM
Re-populating select from db and validate it? - by El Forum - 02-01-2009, 02:14 PM
Re-populating select from db and validate it? - by El Forum - 02-01-2009, 04:29 PM
Re-populating select from db and validate it? - by El Forum - 02-01-2009, 07:16 PM
Re-populating select from db and validate it? - by El Forum - 02-01-2009, 07:31 PM
Re-populating select from db and validate it? - by El Forum - 02-03-2009, 08:35 AM
Re-populating select from db and validate it? - by El Forum - 02-03-2009, 08:39 AM
Re-populating select from db and validate it? - by El Forum - 02-09-2009, 12:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB