CodeIgniter Forums
erro iin adding offset and limit to active record - 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: erro iin adding offset and limit to active record (/showthread.php?tid=40464)



erro iin adding offset and limit to active record - El Forum - 04-09-2011

[eluser]mardon[/eluser]
Hi in my script I want to add pagination and I edit model to
Code:
function getAll($limit = 0, $offset = 0) {
        //$q = $this->db->query('SELECT certs.ser_cislo, certs.pocatek, certs.konec, certs.id_user, users.prijmeni as jmeno FROM certs,users
        //            WHERE certs.id_user = users.id');
        $this->db->select('certs.*');
        $this->db->select('users.prijmeni as jmeno');
        $this->db->from('certs');
        $this->db->join('users', 'certs.id_user=users.id');
        $q = $this->db->get($limit, $offset);
        if ($q->num_rows() > 0) {
            foreach ($q->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }

but after edit i have the error:

A Database Error Occurred

Error Number: 1146

Table 'certifikat.3' doesn't exist

SELECT `certs`.*, `users`.`prijmeni` as jmeno FROM (`certs`, `3`) JOIN `users` ON `certs`.`id_user`=`users`.`id`

Filename: C:\dev\www\ci_certifikat\system\database\DB_driver.php

Line Number: 330

thx for help with my query


erro iin adding offset and limit to active record - El Forum - 04-09-2011

[eluser]toopay[/eluser]
$q = $this->db->select('certs.ser_cislo, certs.pocatek, certs.konec, certs.id_user, users.prijmeni as jmeno')
->join('users', 'certs.id_user=users.id')
->limit($limit, $offset)
->get('certs');


erro iin adding offset and limit to active record - El Forum - 04-09-2011

[eluser]Armchair Samurai[/eluser]
You're missing the first parameter from get() which should be the table name. AFAIK if you want to use the limit and offset parameters, you'll need to either include the table name with the get() call or use the limit() function.

Code:
$this->db->select('c.*, u.prijmeni jmeno');
$this->db->join('users u', 'c.id_user = u.id');

$query    = $this->db->get('certs c', $limit, $offset);

// OR (longer version)

$this->db->select('c.*, u.prijmeni jmeno');
$this->db->from('certs c');
$this->db->join('users u', 'c.id_user = u.id');
$this->db->limit($limit, $offset);

$query    = $this->db->get();



erro iin adding offset and limit to active record - El Forum - 04-09-2011

[eluser]toopay[/eluser]
Code:
$query = $this->db->select('certs.*, users.prijmeni as jmeno')
      ->join('users', 'certs.id_user=users.id')
      ->get('certs',$limit,$offset);



erro iin adding offset and limit to active record - El Forum - 04-09-2011

[eluser]mardon[/eluser]
thx to both, I repair query is and now is OK