我目前正在预订机票。我有的字段/单选按钮/下拉列表是:2单选按钮(单向,往返),2下拉(从,到:),1文本字段。
填写完这些字段后,尝试点击"立即搜索"。它没有返回任何结果。
注意:我的航班表上的列是:flight_name,flight_destination,flight_depart。我还尝试在我的search_result模型和控制器内部打印/ var_dump我的变量,值是正确/正确的
我还尝试打印$ table(它获取我的航班表),$ testing - 获取我的值,$ testing2和$ testing3也是正确的但是当我尝试打印$ query时它是NULL / retuns 0结果。< / p>
模型
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 :(得分:0)
您是否检查过POST变量值?它们是你期望的吗?或者您可以转储后面执行的SQL语句,并尝试查看是否从SQL客户端执行任何结果。
答案 1 :(得分: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();
}