CodeIgniter Forums
Weird query error. Please help :(. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Weird query error. Please help :(. (/showthread.php?tid=13020)



Weird query error. Please help :(. - El Forum - 11-07-2008

[eluser]Lazos[/eluser]
I have this query in my model. I want to extract the last row but I am getting this error:
Fatal error: Call to a member function last_row() on a non-object in D:\websites\dissertation\application\models\admin\content_model.php on line 54

Why this error is occurred? How can I solve it to get the last row?

Code:
function dbContentOrderMany ($parentid, $orderid) {
        $this->db->select('content_id');
        $this->db->from('my_content');
        $this->db->where("parent_id", $parentid);
        $this->db->order_by('item_order', 'ASC');
        $result = $query->last_row('array');
        if ($result == $orderid) {
            return true;    
        }
    }



Weird query error. Please help :(. - El Forum - 11-07-2008

[eluser]mdowns[/eluser]
You are not setting $query.
Try this:
Code:
$query = $this->db->order_by('item_order','ASC');
$result = $query->last_row('array');



Weird query error. Please help :(. - El Forum - 11-07-2008

[eluser]Lazos[/eluser]
I am getting this now.

Fatal error: Call to undefined method CI_DB_mysql_driver::last_row() in D:\websites\dissertation\application\models\admin\content_model.php on line 54


Weird query error. Please help :(. - El Forum - 11-07-2008

[eluser]mdowns[/eluser]
Try a call to get like so.
Code:
$this->db->select('content_id');
        $this->db->from('my_content');
        $this->db->where("parent_id", $parentid);
        $this->db->order_by('item_order', 'ASC');
        $query = $this->db->get();
        $result = $query->last_row('array');



Weird query error. Please help :(. - El Forum - 11-07-2008

[eluser]Lazos[/eluser]
Yes yes that was the problem. In the guide I did not understand that you have to use it too...

Thanks so much.