Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2003
    Location
    .nz
    Posts
    9

    Arrow Unanswered: A better way than this? (next / previous)

    Hi,

    I think it's called 'database paging' in other words limiting the results to a specified # per page and dynamically creating next/previous links accordingly.

    I used this on a site i created a wee while ago and accomplished it by using SQL LIMIT function

    Something like:
    Code:
    f(!isset($page)){
    	$page = 1;
    }
    
    $sqlNum = "SELECT stuff
    FROM table
    WHERE this = that;
    
    $resultNum = mysql_query($sqlNum);
    $numRows = mysql_num_rows($resultNum);
    .....
    
    $perPage = 6;
    $offset = ($page-1)*$perPage;
    
    $sql = "SELECT stuff
    FROM table
    WHERE this = that LIMIT $offset,$perPage";


    This means that you have to run 2 queries instead of 1. It also means that it carries out the query on each page.

    It would be better if it only had the main query which iw carries out once and then somehow limits the actual output and spreads it accross the pages, perhaps some way of putting the results into arrary or caching etc.


    If anyone has suggestions please let me know.
    ?

  2. #2
    Join Date
    Jan 2003
    Posts
    21
    you can mount your result in a table, save it in a session and use it whenever your are not on the first page ..

    In your code, i don't understand the necessity of the first request, you get the number of rows, yes great ... but why ?

  3. #3
    Join Date
    Jan 2003
    Location
    .nz
    Posts
    9
    So that It knows whether there needs to be a 'next' page or not

    I can pass the total number which i get in thr 1st query through the querystring to the next and previous pages which means that 1st query only needs to be carried out on the first page. This is a bit of an improvement i guess.

    I thought putting the results into a session could cause a performence problem due the possible size of the result set?
    Last edited by quadrant6; 01-22-03 at 16:52.

Posting Permissions

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