Welcome Guest, Not a member yet? Register   Sign In
erro iin adding offset and limit to active record
#1

[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
#2

[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');
#3

[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();
#4

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

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




Theme © iAndrew 2016 - Forum software by © MyBB