Контроллер
Код: Выделить всё
public function search(){
$this->form_validation->set_rules('state', 'State', 'required');
$this->form_validation->set_rules('city', 'City', 'required');
$this->form_validation->set_rules('minPrice', 'Minimum Price', 'required');
$this->form_validation->set_rules('maxPrice', 'Maximum Price', 'required');
if ($this->form_validation->run() == FALSE) {
$this->index();
}
else{
$state = $this->input->post('state');
$city = $this->input->post('city');
$minPrice = $this->input->post('minPrice');
$maxPrice = $this->input->post('maxPrice');
$data['hostel_search'] = $this->Hostel_model->search_hostels($state, $city, $minPrice, $maxPrice);
$this->load->view('_parts/header');
$this->index_top();
$this->load->view('search', $data);
$this->load->view('_parts/footer');
}
}
Код: Выделить всё
public function search_hostels($state, $city, $minPrice, $maxPrice){
$state = (int)$state;
$city = (int)$city;
$minPrice = (int)$minPrice;
$maxPrice = (int)$maxPrice;
$query = $this->db->query("SELECT * FROM `hostels` WHERE `state_id`='$state' AND `city_id`='$city' AND `price` BETWEEN '$minPrice' AND '$maxPrice'");
$this->db->from($this->table);
$result = $query->result();
return $result;
}
Код: Выделить всё
[i][b]State[/b][/i]
--Select State--
Подробнее здесь: [url]https://stackoverflow.com/questions/38102214/result-returns-empty-from-codeigniter-model[/url]
Мобильная версия