Developer Developer - 3 months ago 20
MySQL Question

CODEIGNITER: How do I fetch all of the rows that have a due date until tomorrow?

I want to get all the data that have a duedate (tasks_duedate) until tomorrow.

public function getNumDueTomorrowTasks(){
$date = date('Y-m-d H:i:s', strtotime('+1 day'));
$this->db->select('*');
$this->db->from('tasks');
$this->db->where("user_id",$this->session->userdata('user_id'));
$this->db->where("tasks_duedate >", $date);
$this->db->order_by("tasks_id", "desc");
$query_result=$this->db->get();
$result=$query_result->result();
$total = count ($result);
return $total;
}


What am i doing wrong here?

Answer

Haven't had chance to test this myself but, MySQL Between could come into play here.

public function getNumDueTomorrowTasks(){
  $date = date('Y-m-d H:i:s', strtotime('+1 day'));
  $today = date('Y-m-d H:i:s');
  $this->db->select('*');
  $this->db->from('tasks'); 
  $this->db->where("user_id",$this->session->userdata('user_id'));  
  $this->db->where('tasks_duedate BETWEEN "'. $today . '" and "'. $date .'"')
  $this->db->order_by("tasks_id", "desc");    
  $query_result=$this->db->get();
  $result=$query_result->result();
  $total = count ($result);
  return $total;
}