public function get_trayek() {
$transportation=$this->input->post('id_transportation');
$data=$this->main_model->get_trayek($transportation);
$data_trayek='<option value="">----- Pilih Destination -----</option>';
foreach($data as $buff){
$data_trayek.= '<option value="'.$buff->Id_trayek.'">'.$buff->destination.'</option>';
}
$data_trayek1='<option value="">----- Pilih Departure -----</option>';
1.
foreach($data as $buff){
$data_trayek1.= '<option value="'.$buff->Id_trayek.'">'.$buff->departure.'</option>';
}
echo json_encode(array('data'=>$data_trayek));
}
答案 0 :(得分:0)
试试这段代码。
public function get_trayek() {
$transportation=$this->input->post('id_transportation');
$data=$this->main_model->get_trayek($transportation);
$data_trayek='<option value="">----- Pilih Destination -----</option>';
foreach($data as $buff){
$data_trayek.= '<option value="'.$buff->Id_trayek.'">'.$buff->destination.'</option>';
}
$data_trayek1='<option value="">----- Pilih Departure -----</option>';
foreach($data as $buff){
$data_trayek1.= '<option value="'.$buff->Id_trayek.'">'.$buff->departure.'</option>';
}
echo json_encode(array('data'=>array("destination"=>$data_trayek,"departure"=>$data_trayek1));
}
您可以按data.destination
和data.departure
答案 1 :(得分:0)
您可以在单个循环中执行此操作,例如
public function get_trayek() {
$transportation=$this->input->post('id_transportation');
$data=$this->main_model->get_trayek($transportation);
$data_trayek='<option value="">----- Pilih Destination -----</option>';
$data_trayek1='<option value="">----- Pilih Departure -----</option>';
foreach($data as $buff){
$data_trayek.= '<option value="'.$buff->Id_trayek.'">'.$buff->destination.'</option>';
$data_trayek1.= '<option value="'.$buff->Id_trayek.'">'.$buff->departure.'</option>';
}
echo json_encode(array('data'=>array("destination"=>$data_trayek,"departure"=>$data_trayek1));
}