0

これは私のコントローラーです:

<?PHP
class combobox extends CI_Controller 
{

    function dynamic_combobox()
    {

        $this->load->model('combobox_model');       
        $data['college'] = $this->combobox_model->getcollege();
        $this->load->view('header', $data); 
        $this->load->view('left_menu', $data);  
        $this->load->view('manage_user', $data);    
        $this->load->view('footer', $data); 
    }

}

?>

これは私のモデルです:

$this->db->get('colleges'); 
$data = array(); 
if ($query->num_rows() > 0) { 
    foreach ($query->result_array() as $row){ $data[] = $row; } 
} 
$query->free_result(); 
return $data;

これは私の見解です:

<form action="<?php echo site_url(''); ?>" method="post">
    College

    <select name="id" id="id" style="width: 350px;">
        <option class="droplist">Please select colleges</option>
        <?
            if (count($college)>0) 
            {

                foreach ($college as $row) 
                {
                    echo "<option value='". $row['college_id'] . "'>" . $row['college_name'] . "</option>";
                }
            }
        ?>

    </select>
    Courses
    <select>
        <!--<option>UG</option>
        <option>PG</option>-->
    </select>
    <input class="button" type="button" value="Refresh"/>
</form>
4

2 に答える 2

0

私はあなた$queryがあなたのモデルに追加するのを逃したと思います

$query=$this->db->get('colleges'); //<---- here notice $query=
$data = array(); 
if ($query->num_rows() > 0) { 
  $data=$query->result_array();  //<--no need of using loop as you are already looping it in you view
} 
$query->free_result(); 
return $data;
于 2013-07-11T05:57:13.497 に答える
0

それが機能するかどうか試してください、あなたのモデル:

$rs = $this->db->get('colleges'); 
$data = array(); 
if ($query->num_rows() > 0) { 
    $data   = $rs->result_array();
} 
$query->free_result(); 
return $data;

あなたの見解:

if (count($college)>0){
    foreach ($college as $row){
    echo "<option value='". $row['college_id'] . "'>" . $row['college_name'] . "</option>";
    }
}

編集1:

$arr[]    = array('college_id' => '1', 'college_name' => 'Nadar Saraswathi College of Engineering and Technology', 'status' => '1', 'created_by' => '1', 'modified_by' => '1', 'created_date' => '2012-09-30 22:51:25', 'modified_date' => '2012-09-30 22:50:28' );
print_r($arr);
echo "<select>";
foreach ($arr as $row){
    echo "<option value='". $row['college_id'] . "'>" . $row['college_name'] . "</option>";
    }
echo "</select>";
于 2013-07-11T05:57:37.460 に答える