• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
limit in mysql

#1
[eluser]Unknown[/eluser]
im still new about code igniter applications....

Due to my limited know-how....

My question goes like this...

::> $query = $this->db->get('mytable', 10, 20);
which tells about the limit of displaying a record from the 'mytable' database....


but this is not working on me...

i expect the code to display the first two record... but it seems i miss it...

i made a code : $query = $this->db->get('mytable',2);
which display the first two record...


please comment my post.... i want to learn more about code igniter....

#2
[eluser]Michael Wales[/eluser]
Code:
$query = $this->db->get(’mytable’, 10, 20);
Not sure how you could even deduce that would only show the first 2 queries but I will venture to explain what this will show. The query will be:
Code:
SELECT * FROM `mytable` LIMIT 10, 20
This means, start at record 20, and get the next 10 items.

Code:
$query = $this->db->get(’mytable’,2)
This means, start at record 0 (the first record in the table), and get the next 2 items.

#3
[eluser]Unknown[/eluser]
but still the "SELECT * FROM `mytable` LIMIT 10, 20 " query you given to me still not work on me......

The query display none of records....


this is the query i made.. [which mean i sorted the table to its id in decending way]
$this->db->order_by("id", "desc");
$query = $this->db->get('article',2);


but if i gonna use
$query = $this->db->get('article',0,2);
> it display none of records.

#4
[eluser]xwero[/eluser]
[quote author="Cyber Ghost" date="1204871545"]but still the "SELECT * FROM `mytable` LIMIT 10, 20 " query you given to me still not work on me......
[/quote]
If you don't have more than 20 records in that table you won't get any result.

#5
[eluser]dark_lord[/eluser]
I think I might go with xwero's answer.. may be your data in the table are insufficient to show 20 records.. Smile

#6
[eluser]xwero[/eluser]
[quote author="wish_bear" date="1204897606"]I think I might go with xwero's answer.. may be your data in the table are insufficient to show 20 records.. Smile[/quote]
I think you got the wrong idea the get method puts the limit before the offset which could confuse some people because in the (my)sql statement it's the other way around.
Code:
$this->db->get('table',10,20);
Returns
Quote:SELECT * FROM table LIMIT 20,10
So you need to have over 20 records. If you have 21 records you get one record as result.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.