Welcome Guest, Not a member yet? Register   Sign In
usage of limit from direct sql writing vs $this->db->limit
#1

[eluser]fs_xyz[/eluser]
I guess, I end up bothering you people with loads of questions. -_-

Why does it always produce error message when parsing offset into normal sql query writing ?

Example :
$this->db->query('select * from table limit'.$offset.','.$limit'');

What I parsed into $offset is $this->uri->segment(3).
Yes, this is about pagination.
That always produce an error, $offset doesn't have a value.
I thought I misplaced them, so I switch their place but still the same.

But if I use :
$this->db->select('*');
$this->db->from('table');
$this->db->limit($limit,$offset);
It always work. Yes, using the same parsing value which is $this->uri->segment(3).

I choose using $this->db->query, freedom to write query is quite large compared to use template like $this-db->select. Problem is that limit. Wonder how to make it work if the parsed info is $this->uri->segment(3). ( or whatever number inside the bracket )

Previous 2 questions already had simple answer, hopefully this one won't make me face palm again.....
#2

[eluser]Colin Williams[/eluser]
Looks like you just need a space after limit. Your query would look like 'select * from table limit0,3'
#3

[eluser]fs_xyz[/eluser]
No, I can assure you it is not about space... I wrote it in the wrong way at my 1st post.
If just because of space, it won't show error message because no value assigned....
#4

[eluser]saidai jagan[/eluser]
Check
Code:
if($offset)
  $offset=$offset;
else
  $offset = 0;
#5

[eluser]renownedmedia[/eluser]
If it doesn't get a value you get a blank string, not the zero as you're assuming, which results in a mysql syntax error.
#6

[eluser]fs_xyz[/eluser]
After using Grad Student's checker... it is working now.
Wonder if $this->db->limit also include such checker tough.




Theme © iAndrew 2016 - Forum software by © MyBB