codeigniter
2016-09-30 4 views 0 likes 
0

Code Igniterのデータベースからドロップダウンフィールドにデータを取得しようとしています。ここにコードはあります:Codeigniter:Auto Fill DropDown From databaseが機能しない

<input type="hidden" 
     id="tour_package_id" 
     class="form-control" 
     name="tour_package_id" /> 
<?php $i='class="form-control" 
      name="tour_name" 
      id="tour_name"'; 
      echo form_dropdown('tour_package_id', $tour_list, 
          set_value('tour_package_id', $tour_package_id),$i);?></div> 

私はそのために次のエラーが発生しています。

Severity: Notice 
Message: Undefined variable: tour_package_id 
Filename: Packages/add_location.php 
Line Number: 40 

すべてのものを試しましたが、動作しません。

おかげ Bhagya

+0

この問題を解決するには、次の点を確認してください。http://stackoverflow.com/questions/19922143/display-data-from-database-to-dropdown-codeigniter –

答えて

0

は、コンボボックスの右のドロップダウンですか?

これを試してみてください(これはハードコードだけでそれを変更する場合)

例:

Table(tbl_Category) 
    ID | Category_Name 
    1  Hardware 
    2  Software 



    Model 
    public function getCategory(){ 
      $this->db->select('*'); 
      $this->db->from('tbl_Category'); 
      $query = $this->db->get(); 
      return $query; 
    } 

    Controller(The trigger to view)(load the model also) 
     public function show(){ 
     $this->data["result"] = $this->Model->getCategory(); 
     $this->load->view('Category',$this->data); //this->data will get the result value to your view 
     } 

    The view(Category.php) 
    <select> 
     <?php foreach($result as $results){ ?> 
     <option value="<?php echo $results->ID; ?>"><?php echo $results->Category; ?></option> 
     <?php } ?> 
    </select> 

選択内側のforeachはそれは素晴らしいになります!私はカテゴリを追加するようにオプションが自動的に追加されますように!これを試して!お役に立てれば!

関連する問題