在codeigniter项目中获取一个空数组

时间:2015-10-16 10:08:19

标签: php mysql codeigniter

在下面的代码中,我得到第三个if-else语句的空数组。我正在尝试的是从用户获取一系列日期并相应地显示表中的数据。我的第一个if-else语句是返回所需的结果,但第二个是返回空数组。

控制器:

404 Not Found

模型 public function bookings() { if($this->userlib->isLoggedIn()) { if($this->userlib->isAdmin()) { $this->load->view('admin_search_booking'); $date_posted_from = $this->input->post('date_posted_from'); $date_posted_till = $this->input->post('date_posted_till'); $date_posted_on = $this->input->post('date_posted_on'); if(is_null($date_posted_from) && is_null($date_posted_till) && is_null($date_posted_on)) { $total_trails = $this->admin_panel_model->total_trail(); var_dump($total_trails); } elseif(!is_null($date_posted_on)) { $total_trails = $this->admin_panel_model->filter_on_date($date_posted_on); var_dump($total_trails); } elseif(!is_null($date_posted_from) && !is_null($date_posted_till)) { $total_trails = $this->admin_panel_model->filter_by_date($date_posted_from, $date_posted_till); var_dump($total_trails); } } } else { echo "User not Logged In"; } } : -

filter_by_date

isLoggedIn: -

public function filter_by_date($date_posted_from, $date_posted_till)
{
    $query = $this->db->select('*')
                      ->where('date >=', $date_posted_from)
                      ->where('date <=', $date_posted_till)
                      ->get($this->search);
    return $query->result();
}

3 个答案:

答案 0 :(得分:0)

像这样更改模型功能

Meteor.startup(function () {
  if (Collection.find().count() === 0) {
    console.log("Importing private/collection.json to db")

    //grabs data from exported json file
    var data = JSON.parse(Assets.getText("collection.json"));

    //adds it to your collections
    data.forEach(function (item, index, array) {
      Collection.insert(item);
    })
  }
});

答案 1 :(得分:0)

//This may help you put your table name in your select statement and update where clause
public function filter_by_date($date_posted_from, $date_posted_till){
       $date_posted_from='2015-10-10';
        $date_posted_till='2015-10-16';
        $query = $this->db->select('*')->from('Your_Table_Name')
                          ->where("date >= '".$date_posted_from."'")
                          ->where("date <= '".$date_posted_till."'")
                          ->get($this->search);
        return $query->result();
    }

答案 2 :(得分:0)

使用$ this-&gt; db-&gt; last_query();在filter_by_date()之后,检查实际执行的查询。并确保您要搜索的日期范围中存在记录。 或者只是使用直接查询,

$Q = $this->db->query("select * from table_name where date >='".$date_posted_from."' and date <='".$date_posted_to."'");
return $Q->result_array();