2017-04-03 69 views
0

我呼籲no.tpl頁面,在此頁面時在select dropdownOpencart的獲取選擇值控制器,用於過濾

這顯示客戶名稱是代碼: no.tpl

<select name="customer_id" id="customer" style="width: 325px;margin-bottom:10px" class="form-control"> 
    <?php foreach($customerData as $customer){ ?> 
     <option value=<?php echo $customer['customer_id']?>><?php echo $customer['customer_name']?></option> 
    <?php }?> 
</select> 

在控制器頁我要篩選出特定的客戶名單

$queryCustomer = $this->db->query("select customer_id, concat(firstname, ' ',lastname) as name, email from " . DB_PREFIX . "customer where customer_id='6'"); 
      $selectedCustomer = $queryCustomer->row; 
      $selectedCustomerId = $selectedCustomer['customer_id']; 
      $selectedCustomerName = $selectedCustomer['name']; 
      $selectedCustomerEmail = $selectedCustomer['email']; 

我想要customer_id='6'選爲customer_id。我的意思是通過選擇值到控制器頁面

回答

1

鑑於網頁試試這個代碼

<select name="customer_id" id="input-sales-person" style="width: 325px;margin-bottom:10px" class="form-control"> 
    <?php foreach($customerData as $customer){ ?> 
     <option id="temp" value=<?php echo $customer['customer_id']?>><?php echo $customer['customer_name']?></option> 
    <?php }?> 
</select> 

<input type="submit" id="noOrder" Onclick="return ConfirmDelete();" value="Submit" class="btn btn-primary"> 

使用此下面的腳本

<script type="text/javascript"> 
    $('#noOrder').on('click', function() { 
     var temp1=$("#input-sales-person option:selected").val(); 
     var temp2=$("#input-sales-person option:selected").text(); 
     document.cookie = "selectedCustomerId=" +temp1; 
     document.cookie = "selectedCustomerName=" +temp2; 
     location="index.php?route=sale/no"; 
    }); 
</script> 

在控制器通過customer_id$selectedCustomerId=$_COOKIE['selectedCustomerId'];

$selectedCustomerId=$_COOKIE['selectedCustomerId']; /*customer_id=6*/ 

$queryCustomer = $this->db->query("select customer_id, concat(firstname, ' ',lastname) as name, email from " . DB_PREFIX . "customer where customer_id='".$selectedCustomerId."'");