• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to repopulate select generated from database? anyone can help me?

#1
[eluser]zoreli[/eluser]
Hi

I am trying to repopulate my select meny which is generated from database:

Here is my code:

Code:
echo "<select name='parentid'" . set_value("parentid"). ">";
    echo '<option value = "0">None</option>';
    foreach ($faq_categories as $row => $option) {
        echo "<option value=" . $option['catid'] . ">" . $option['categoryname']. "</option>";
    }
    echo '</select>';

Above code does not work. Any help will be deeply appreciated.

Regards, Zoreli

#2
[eluser]CroNiX[/eluser]
Post the query you run to generate $faq_categories.

#3
[eluser]Matalina[/eluser]
Typically I do the following:
Code:
echo form_dropdown('parentid',$faq_categories,set_value('parentid',$value);

where $faq_categories would be in the format of array($value1 => $option_text2, $value2 => $option_text 2....);
and where $value is the default value which is optional

Of corse need to have the form helper loaded in the controller

#4
[eluser]zoreli[/eluser]
[quote author="CroNiX" date="1330627919"]Post the query you run to generate $faq_categories.[/quote]

Hi

Here is my controller code:

Code:
public function displayAddFaqCategoryForm($error = null)
        {
            $data['title'] = "Add new FAQ Category";
            $data['main_content'] = 'addFaqCategory';
            $selectWhat = array('tname' => 'faq_categories',
                                'sortby'=> 'catid',
                                'how'   => 'asc'
                                );
            $this->load->model('selectRecords');
            $data['faq_categories'] = $this->selectRecords->selectAllRecords($selectWhat);
            $this->load->vars($data);
            $this->load->view('backOffice/template');
        } // end of function displayAddFaqCategoryForm

And here is the model code:

Code:
public function selectAllRecords($selectWhat = array())
        {
            $data = array();
            $tname = $selectWhat['tname'];
            $sortby = $selectWhat['sortby'];
            $how = $selectWhat['how'];
            $this->db->order_by($sortby,$how);
            $query = $this->db->get($tname);
            if($query->num_rows() > 0)
            {
                foreach($query->result_array() as $row)
                {
                    $data[] = $row;  
                }
            }
            $query->free_result();
            return $data;
        } // end of function selectAllRecords

Regards, Zoreli

#5
[eluser]zoreli[/eluser]
Shameless bump :-)


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.