I have a query like this:
SELECT RIGHT(id, 1) id_root
FROM user
WHERE LENGTH(id) = 3
and LEFT(id, 1) = '0'
And how to convert that's query to active record in codeigniter
.
My problem is with syntax RIGHT( id, 1 )
and also at LEFT(id,1)='0'
$result_arr = $this->db
->select("RIGHT(id, 1) id_root", FALSE)
->from("user")
->where(
array("LENGTH(id)"=> 3, "LEFT(id, 1) =" => 0)
)->get()
->result_array();
Or you can simply use $this->db->query("You SQL");
$query = "SELECT RIGHT(id, 1) id_root
FROM user
WHERE LENGTH(id) = ?
and LEFT(id, 1) = ? ";
$result_arr = $this->db->query($query, array(3, 0))->result_array();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With