gadss
gadss

Reputation: 22519

CodeIgniter equivalent code for SQL Query

I have this query and I want to put it on my code igniter php.

SELECT MAX(IDnumber) FROM student WHERE IDnumber LIKE '2013256%'

I trued this one but it returns error:

$this->db->select_max('IDnumber');
$this->db->get('student');
$IDnumber = $this->db->like('IDnumber', '2013256', 'after'); 
return $IDnumber;

does anyone have an idea about my case? thanks in advance...

Upvotes: 1

Views: 100

Answers (1)

Egor Sazanovich
Egor Sazanovich

Reputation: 5089

You are getting result after $this->db->get(), so use

$this->db->select_max('IDnumber');
$this->db->like('IDnumber', '2013256', 'after'); 
$this->db->from('student');
return $this->db->get();

Also You can use chaining method:

return $this->db->select_max('IDnumber')->like('IDnumber', '2013256', 'after')->get('student');

Upvotes: 5

Related Questions