我目前正在進行航空預訂。我有的字段/單選按鈕/下拉列表是:2個單選按鈕(單向,往返),2個下拉(從,到:),1個文本字段。在多個條件下返回零結果codeigniter
填滿這些字段並嘗試點擊「立即搜索」。它不返回結果。
注:我在飛機上表中的列有:flight_name,flight_destination,flight_depart。我也嘗試在我的search_result模型和控制器中打印/ var_dump我的變量,值正確/正確
我也嘗試打印$表(它讓我的航班表),$測試 - 獲取我的價值, $ testing2和$ testing3也是正確的,但當我試圖打印$查詢時,它是NULL/retuns 0結果。
型號
public function search($table, $flight_from, $flight_to, $depart)
{
$this->db->select('*');
$table = $this->db->from($table);
$testing = $this->db->where('flight_name',$flight_from)
$testing2 = $this->db->where('flight_destination',$flight_to)
$testing3 = $this->db->where('flight_depart',$depart);
$query = $this->db->get();
return $query->result();
}
控制器
public function search()
{
$this->form_validation->set_error_delimiters('<div class="alert alert-danger" role="alert">', '</div>');
$this->form_validation->set_rules('flight_from', 'Select depature', 'required|trim');
$this->form_validation->set_rules('flight_to', 'Select Destination', 'required|trim');
$this->form_validation->set_rules('depart', 'Date', 'required|trim');
if ($this->form_validation->run() == FALSE)
{
$this->index();
}
else
{
$search_result = array(
$flight_from = $_POST['flight_from'],
$flight_to = $_POST['flight_to'],
$depart = $_POST['depart']
);
$data['search_result'] = $this->CrudModel->search('flight',$flight_from,$flight_to,$depart);
$this->load->view('result',$data);
}
}
問:它是如何返回結果爲零?即使有一個現有的數據。我的查詢錯誤了嗎?
是的,我已經檢查它的第n次..即時通訊所獲得的價值也是正確的 – Angel
怎麼樣的SQL查詢語句,如果是手動執行,你得到什麼結果?我的意思是轉儲$ this-> db-> get() - > getSQL(); – BDS
那麼它會變成這樣嗎? $ query = $ this-> db-> get() - > getSQL();?如果是,它會給我一個錯誤消息:調用未定義的方法CI_DB_mysqli_result :: getSQL() – Angel