1

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 ''3'' at line 1

SELECT * FROM tbl_testimoni order by id DESC limit 3 offset '3'

Filename: D:\wamp\www\obatrohanifinalcopy\system\database\DB_driver.php

Line Number: 330

I'm having problem with my query syntax. I think the problem is in limit and offset query. Because I have tried without limit and offset and my script can work properly. But the pagination function doesn’t work according to my wish.

This is my controller:

$url = $this->uri->segment(3, 0);
$this->load->library('pagination');
$config['base_url'] = site_url() . '/testimonial/all/';
$config['total_rows'] = $this->db->get('tbl_testimoni')->num_rows();
$config['per_page'] = 3;
$this->pagination->initialize($config);
$data['page']=$this->pagination->create_links();
        
$sql = " SELECT * FROM tbl_testimoni order by id DESC limit 3 offset ? ";
$binds = array($url);
$query = $this->db->query($sql, $binds);
$artikel = $query->result_array();
$data['action'] = 'testimonial/all';
$data['artikel'] = $artikel;
$data['content'] = 'content/testimoni';
$this->load->view('template/default', $data);

and in my view the pagination was called using this code:

<?php if(!empty($page)) echo $page; ?>

and my code doesn’t work properly.

Note: I was using this controller and view in my previous website but there I was using PostgreSQL and it worked.

2 Answers 2

1

Try typecasting the $binds variable as in $this->db->query($sql, intval($binds));

Also, by the documentation $this->uri->segment() may return boolean, so you might want to handle that as well.

Sign up to request clarification or add additional context in comments.

1 Comment

still same like before sir. the result on next pagination still same like first page. not appears the next data
0

The offset should be a number not string '3'

when you pass the $binds in $this->db->query($sql, $binds); the DB Driver think its a value and replace your ? with '3' where it should be OFFSET 3

2 Comments

results are not performing well. just called multiple databases and when I click on the pagination. the result is the same as the start page appears
If its give always same result then the problem could be in the url segment, can you check what value you are getting from your uri segment also you can echo $this->db->last_query() to see the last query what exactly its executing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.