Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2002
    Location
    United Kingdom
    Posts
    1,236

    help with mysql's LIMIT

    OK i have been stuck on this for hours

    first of all this script shows results from rows in a table.

    well, first off here is the code :

    PHP Code:
            $cat $_GET['cat'];
            
    $search_type $_GET['search_type'];
            
    $search_data $_GET['search_data'];
            
    $from $_GET['from'];
            
    $to $_GET['to'];
            
    $counter 1;

            
    $fetch_reviews "SELECT postid, review_name FROM $cat WHERE review_name LIKE '%' LIMIT $from$to";
            
    $result mysql_query($fetch_reviews);

            while(
    $data mysql_fetch_row($result))

            {

                echo(
    $data[1].'<BR>');
                echo(
    '<a href="edit.php?postid='.$data[0].'">Edit</a>');
                echo(
    '<BR><BR>');
                
    $counter ++;


            }
            
            if(
    $from != 0)

            {

                
    $previous_to $to 10;
                
    $previous_from $from 10;
                echo(
    '<a href="search.php?cat='.$cat.'&search_type='.$search_type.'&search_data='.$search_data.'&mode=edit3&from='.$previous_from.'&to='.$previous_to.'">Previous Page</a> ');

            }


            if(
    $counter 10)

            {

                
    $next_to $to 10;
                
    $next_from $from 10;
                echo(
    '<a href="search.php?cat='.$cat.'&search_type='.$search_type.'&search_data='.$search_data.'&mode=edit3&from='.$next_from.'&to='.$next_to.'">Next Page</a>');

            } 
    now then what that code is meant to do is display results, and if there are more than 10 results in the table, then show a next page link

    ok that works but i have a problem

    there are eighteen matches in the table.

    now when limit is LIMIT 0, 10 it displays the first 10 matches and then the nextpage link

    when limit is LIMIT 10, 20 it shows, for some reason, all 18 matches, why???

    then when limit is LIMIT 20, 30 it shows the last 8 pages, which should have been showed by LIMIT 10, 20

    can anyone see what is wrong with my script???

    Thanx

  2. #2
    Join Date
    Jun 2002
    Location
    United Kingdom
    Posts
    1,236
    ahhhh i found the problem

    i miss understood LIMIT

    i thought the first number of LIMIT was the row it goes from and the secound number was the row it goes to.

    but its not, the second number is how many results it displays (matching the query u set) and the first number is where it starts from.

    so that last number should always be 10

    thanx anyway

    Matt Jones

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •