0

Good Day Masters, Can anyone help me how to convert this SQL Query into Code Igniter format (model).

SELECT firstName,  FLOOR(DATEDIFF(CURRENT_DATE, birthDate)/365.25) as age  FROM residents_tbl WHERE  FLOOR(DATEDIFF(CURRENT_DATE, birthDate)/365.25) >= 18

I don't know how to write it on WHERE clause.

    $query = $this->db->select('*');
    $query = $this->db->from('residents_tbl');
    **$query = $this->db->where('isHead', '1');**
    $query = $this->db->order_by('lastName', 'ASC');
    $query = $this->db->get('', 15, $this->uri->segment(3));
    if ($query->num_rows() > 0) {
        return $query->result();
    }

TIA.

Pradeep
  • 9,667
  • 13
  • 27
  • 34
ChocoMartin
  • 111
  • 1
  • 3
  • 12

1 Answers1

1

This is a simplified version with chaining. I just changed the type of 1 from string to number which might caused the problem.

$query = $this->db
         ->where('isHead', 1)
         ->get('residents_tbl')
         ->order_by('lastName', 'ASC');
gazdagergo
  • 6,187
  • 1
  • 31
  • 45