dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: Help with pagination!!!!

  1. #1
    Join Date
    Mar 2008
    Posts
    32

    Help with pagination!!!!

    Hi all!

    So, I have a website for a database which contains biological data (proteins). In this website, there is a text search page,
    where the user can specify one or more search terms in order to get data from the database. The user can enter up to 5 search terms in each of the
    available text boxes, as shown below in text_search.php

    The retrieve_text.php page gets the data submitted by the user and fetches the results. Also, if the user clicks on 1 or more of the
    checkboxes next to each record, the respective entries are downloaded as raw format archives.
    However, because in some cases there were more than 200 results
    I decided to implement pagination... I searched around and asked for help, and managed to get it as far as you see below.

    My problem is that, although the state of the selected entries is maintained as the user browses from page to page, this is NOT the
    case for the $wclause_sql part, which is actually the "WHERE" clause of the sql query. So I can only see the first page, and not the others...

    I used sessions in order to keep track which records are selected by the user, so as when the user finally hits 'Retrieve'
    he can get all the desired entries, but I cannot transfer the $wclause and therefore, in all other pages except page 1, the SQL query is empty, thus no
    entries are shown.

    What am I missing here?
    Attached Files Attached Files

  2. #2
    Join Date
    Nov 2006
    Location
    Oakland
    Posts
    500
    You have to create a query string including all the search parameters sent in the initial request. Let's suppose you have 5 search terms with names s1, .., s5

    Because your initial search queries determines the total number of results (rows) your can calculate the total number of pages:

    $npages=rows/rows_per_pages

    Defines a parameter named cursor which is tied to the page currently viewed.
    cursor=0 for the first page, cursor=1 for the second page and so on.


    Your pagination URL would be something like:

    <a href="http://yoursite.com/retrieve_text.php?np=$npages&cs=0&s1=term1&s2=term2&s3=term3&s4=term4&s5=term5">1</a> <a href="http://yoursite.com/retrieve_text.php?np=$npages&cs=1&s1=term1&s2=term2&s3=term3&s4=term4&s5=term5">2</a>
    <a href="http://yoursite.com/retrieve_text.php?np=$npages&cs=3&s1=term1&s2=term2&s3=term3&s4=term4&s5=term5">3</a> ....

    Notice only the value of the cursor (cs) change in each hyperlink href attribute and the number of the page 1, 2, 3.

    Make sure the term1, ..., term5 are url encoded.

    I assume in the retrieve_text.php you have two operations (functions):
    - one that only determines the number of results when the request comes from text_search.php
    - a second that retrieves only one page, according to the current value of the cursor

    The reason being, you determine the number of results once when the new search terms are defines. Afterwards, you know how many pages of results that query has.

    $cursor -> $_GET['cs'] (make sure it's a numeric)
    $limit -> rows_per_pages
    $skip=$limit * $cursor

    $sql="SELECT .... WHERE .... Limit $skip, $limit;

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles