如何通過選擇的下拉菜單自動填充數據庫中的數據? 和我的下拉結果已經出現爲好,代碼如下:根據下拉選擇自動填充,需要幫助
<?php
echo '<tr>
<td>'.$customer.'</td>
<td><select name="customer_id">';
foreach ($customers as $customer) {
if ($customer['customer_id'] == $customer_id) {
echo '<option value="'.$customer['customer_id'].'" selected="selected">'.$customer['name'].'</option>';
} else {
echo '<option value="'.$customer['customer_id'].'">'.$customer['name'].'</option>';
}
}
echo '</select>
</td>
</tr>';
?>
和下拉的結果上面列出的
- 管理
- customer1表
- 免費
從以下db加載
INSERT INTO `my_customer` (`customer_id`, `name`, `firstname`, `lastname`) VALUES
(8, 'admin', '', ''),
(6, 'customer1', 'ok', ''),
(7, 'FREE', 'marj', 'om');
所以每當下拉列表中選擇我想下面的所有數據:
<tr>
<td><?php echo $firstname; ?></td>
<td><?php echo $lastname; ?></td>
</tr>
也自動填入,它似乎需要的JavaScript/AJAX/jQuery來固定它,我想知道,如果有人可以幫助我,謝謝提前
Addtion JSON CALL
我有JSON通話已經是小號以下: (讓說這話放在customer.php網址爲的index.php P =頁/客戶?)
public function customers() {
$this->load->model('account/customer');
if (isset($this->request->get['customer_id'])) {
$customer_id = $this->request->get['customer_id'];
} else {
$customer_id = 0;
}
$customer_data = array();
$results = $this->account_customer->getCustomer($customer_id);
foreach ($results as $result) {
$customer_data[] = array(
'customer_id' => $result['customer_id'],
'name' => $result['name'],
'firstname' => $result['firstname'],
'lastname' => $result['lastname']
);
}
$this->load->library('json');
$this->response->setOutput(Json::encode($customer_data));
}
和DB
public function getCustomer($customer_id) {
$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "customer WHERE customer_id = '" . (int)$customer_id . "'");
return $query->row;
}
究竟是什麼你試圖做...嘗試重新短語你的問題,使人們可以正確地理解它。 – 2011-05-04 12:38:31