2017-06-04 17 views
0

我目前正在进行航空预订。我有的字段/单选按钮/下拉列表是: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); 
     } 
    } 

问:它是如何返回结果为零?即使有一个现有的数据。我的查询错误了吗?

回答

0

你检查了你的POST变量值吗?他们是你所期望的吗?或者,您可以转储后面执行的SQL语句,并尝试查看是否从SQL客户端获得任何执行结果。

+0

是的,我已经检查它的第n次..即时通讯所获得的价值也是正确的 – Angel

+0

怎么样的SQL查询语句,如果是手动执行,你得到什么结果?我的意思是转储$ this-> db-> get() - > getSQL(); – BDS

+0

那么它会变成这样吗? $ query = $ this-> db-> get() - > getSQL();?如果是,它会给我一个错误消息:调用未定义的方法CI_DB_mysqli_result :: getSQL() – Angel

0
public function search($table, $flight_from, $flight_to, $depart) 
{ 
    $this->db->select('*'); 
    $this->db->from($table); 
    $this->db->where('flight_name',$flight_from) 
    $this->db->where('flight_destination',$flight_to) 
    $this->db->where('flight_depart',$depart); 
    $query = $this->db->get(); 
    return $query->result(); 
}