CodeIgniter Forums
Pagination using $this->db->query - 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: Pagination using $this->db->query (/showthread.php?tid=34794)



Pagination using $this->db->query - El Forum - 10-09-2010

[eluser]christiaan001[/eluser]
Hi there,

Please forgive me but I am having trouble passing $offset when using pagination within $this->db->query. I can pass $num,$offset using $this->db->get with no problems.

Please see code:

Code:
function getAllUser($num, $offset)
    {
     $query = $this->db->get('tbluser', $num,$offset);    
     return $query->result();
    }

The above function works fine:

The function below produces a database error.

Code:
function getAllUser($num, $offset)
        {
          $query = $this->db->query("SELECT intUserID, strFirstName, strSurname,  strEmail,datRegistration, AES_DECRYPT(strEncrypt,'key :) ')
          AS strEncrypt, strUserType      
          FROM tbluser  
          ORDER BY intUserID
          Limit '$num','$offset'");    
          return $query->result();
        }

Database error:

A Database Error Occurred
Error Number: 1064

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' '5',''' at line 1

select * from tblimage Limit, '5',''

If anyone can point out where I am going wrong muchly appreciated


Pagination using $this->db->query - El Forum - 10-13-2010

[eluser]deepydee[/eluser]
'.$num.', '.$page.'