Welcome Guest, Not a member yet? Register   Sign In
problem with the function limit()
#1

[eluser]Kenan[/eluser]
hi everybody) i have started learn the ci just a few days ago and absolutely myself so dont laugh please Smile

so, i'm trying select 7 rows from the db starting from $start, when i use classic mysql_query("SELECT ...... LIMIT $start, 7",$db); it works perfectly, but when i do this:

$this->db->order_by('id','desc');
$this->db->limit(7,$start);
$this->db->where('cat',$cat);
$this->db->where('lesson',$lesson);
$query = $this->db->get('comments');

it works incorrect, the rows displaying shuffle intead of descending, and if the value of $start more than 60, it displaying nothing, as if there is no row in th field

i have read all doc, a lot of docs from other sites, but no result, what is worng? advice me right way please Smile
#2

[eluser]Kenan[/eluser]
up
#3

[eluser]Kenan[/eluser]
upp
#4

[eluser]InsiteFX[/eluser]
You need to increment $offset to get the next 7 limited records from the database.

Code:
function your_name($cat, $lesson, $limit, $offset)
{
    $limit  = (int) $limit;
    $offset = (int) $offset;

    $this->db->order_by('id', 'desc');
    $this->db->where('cat', $cat);
    $this->db->where('lesson', $lesson);
    $query = $this->db->get('comments', $limit, $offset);
}
#5

[eluser]Kenan[/eluser]
thanks a lot but i cant do it, because $offset ($start in my exampe) i get from db:

Code:
$data['com'] = $this->db->count_all('lcomments');
$start = $data['com'] - 7;

so i cant define it in the url or somewhere else, any other idea?)
#6

[eluser]Kenan[/eluser]
by the way, i have tried your advice manually giving a value to the offset but the same result, no solution, so pity :/
#7

[eluser]InsiteFX[/eluser]
Users Guide Pagination Class
#8

[eluser]Kenan[/eluser]
i sincere gratitude my dear friend but i mustnt use the pagination, pagination only for the lesson, for the comments i must use ajax to load previous comments, so for the first time (while 'show prev coms' not pressed) should displayed just last 7 comments, by pressing another 7 comments will prepend and so on)
#9

[eluser]InsiteFX[/eluser]
Well you never mentioned anything about ajax loading.

Show your Ajax code and for the s in script use a $ ( $cript ) ( /$cript )

#10

[eluser]Kenan[/eluser]
this is my ajax code but i cant understand how that depends on it Smile
because in classic php (without ci) it works perfectly even without this code, how can it affect to displaying the first 7 comments? o.O

Code:
var start = $('.comment').length;
$('#more').live('click', function() {
  if (start > 0) {
   $('#loading').show();
   $.ajax({
    url: 'prev_comments.php?cat=<?php echo $cat; ?>&lesson;=<?php echo $lesson; ?>&start;=' + start,
    cache: false,
    success: function(html) {
     setTimeout(function () {
      $('#loading').hide();
      $(html).prependTo('#comments');
     }, 500);
     start -= 7;
    }
   });
  }
  else if (start <= 0) {
   $('#more').hide();
   $('#noMore').fadeIn(700);
   setTimeout(function () {
    $('#noMore').hide();
    $('#more').fadeIn();
   }, 2500);
  }
});




Theme © iAndrew 2016 - Forum software by © MyBB