2016-05-27 6 views
0

私は、ドロップダウンにデータベーステーブルの値が入力されるPHPフォームを使用しています。他のドロップダウンの値に応じてドロップダウンを設定します

$options_demande['orderBy'] = array('id_produit' => 'ASC'); 
    $options_demande['items'] = array('produit'); 
    $data['id_produit'] = $this->produit_model->getListCombo('*',null,$options_demande,'Sélectionner un produit'); 
$options_demande['orderBy'] = array('id_abonnement' => 'ASC'); 
    $options_demande['items'] = array('abonnement'); 
    $data['id_abonnement'] = $this->abonnement_model->getListCombo('*',null,$options_demande,'Sélectionner un abonnement'); 

getListCombo方法:

public function getListCombo($select = '*', $conditions = array(), $optional = null, $first_line = null) 
{ 
    $dropdown = array(); 
    if ($select != null) 
     $this->db->select($select)->from($this->table); 

     if (isset($conditions['where'])) 
     $this->db->where($conditions['where']); 

     if (isset($conditions['where_in'])) 
     $this->db->where_in($conditions['where_in']); 

     if (isset($conditions['where_or'])) 
     $this->db->or_where($conditions['where_or']); 

     if (isset($conditions['like'])) 
     $this->db->like($conditions['like']); 

     if (isset($conditions['like_or'])) 
     $this->db->or_like($conditions['like_or']); 

    if (isset($optional['orderBy'])) 
     foreach($optional['orderBy'] as $order => $val) 
      $this->db->order_by($order,$val); 

    $rs = $this->db->get()->result_array(); 

    if (isset($first_line)) 
    { 
     if (is_array($first_line)) 
      $dropdown[$first_line['k']] = $first_line['v']; 
     else 
      $dropdown[''] = $first_line; 
    } 
    foreach($rs as $item){ 
     $liste = null; 
     foreach($optional['items'] as $item_liste){ 
      $liste .= $item[$item_liste]." "; 
      $dropdown[$item['id_' . $this->table]] = $liste; 
     } 
    }  

    return $dropdown; 
} 

事は、私は他のドロップダウンが他のテーブルの特定の値が移入させたいということです。

私のドロップダウンのコード:

<div class="form-group"> 
       <label class="col-md-2 control-label" for="id_produit"><?php echo lang('produit'); ?><span class="required"> * </span></label> 
       <div class="col-md-4"> 
       <?php echo form_dropdown('id_produit', $id_produit, null,'class="form-control" required="required"')?> 
       </div> 
      </div> 
<div class="form-group"> 
       <label class="col-md-2 control-label" for="id_abonnement"><?php echo lang('abonnement'); ?><span class="required"> * </span></label> 
       <div class="col-md-4"> 
       <?php echo form_dropdown('id_abonnement', $id_abonnement, null,'class="form-control" required="required"')?> 
       </div> 
      </div> 

私はいくつかのJavaScriptを使用するように持っていると思うが、私はそれを行う方法がわかりません。

もう一方のテーブルには他のテーブルのすべての値が入力されていますが、最初のドロップダウンリストの特定の値については、もう一方のテーブルには " type_abonnement "= 1または他の値の場合は2です。

My dropdowns

Display values where Type_abonnement = 0 for example

答えて

関連する問題