2017-08-09 42 views
0

我有一個下拉列表與數據庫中的客戶名稱。我希望這些值能成爲我的'href'屬性的鏈接。我該怎麼做?下拉與php鏈接

<select class="feedback-input" id="customer_selecter" name="customerName"> 
      <option >Select customer</option> 
      <?php foreach ($customers as $row): ?> 
       <a href="<?php echo base_url() . "index.php/edit/show_customer_id/" . $row->customerID; ?>"> 
      <?php echo '<option value="'.$row->customerID.'">'.$row->customerName.'</option>'; ?></a> 
      <?php endforeach; ?> 
     </select> 
+3

[使用href鏈接內部

回答

0

試試這個:

<select class="feedback-input" id="customer_selecter" name="customerName"> 
    <option >Select customer</option> 
    <?php foreach ($customers as $row): ?> 
     <a href="<?php echo base_url() . 'index.php/edit/show_customer_id/' . $row->customerID; ?>"> 
      <option value="<?php echo $row->customerID; ?>"><?php echo $row->customerName; ?></option> 
     </a> 
    <?php endforeach; ?> 
</select> 

但這不是一個有效的HTML,因爲您使用的是<select>標籤內<a>標籤,嘗試用JavaScript這樣做,而不是像這樣:

<select class="feedback-input" id="customer_selecter" name="customerName" onchange="location = this.value;"> 
    <option >Select customer</option> 
    <?php foreach ($customers as $row): ?> 
     <option value="<?php echo base_url() . 'index.php/edit/show_customer_id/' . $row->customerID; ?>"><?php echo $row->customerName; ?></option> 
    <?php endforeach; ?> 
</select> 
+0

謝謝你,但它不適合我:( – Ksenia

+0

@Ksenia嘗試秒的方法 – yoeunes

+0

謝謝你很多!!!太棒了! – Ksenia