SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2010
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pagination - insert columns into database

    I am trying to 'paginate' a table with 15 input fields, having 5 fields in a different page.

    I have managed to work some code into doing that for one row (retrieved from a database).

    However, i can't seem to break the input fields into fives like the first row - they all display in one page (attached image). I can loop and display results from the database fine, but looping the HTML input fields is the problem.

    How i do i loop the fields so that for each set of 5 results, i have 0-4, 5-9 and 10-14 input fields? All the tutorials i have come across only deal with database results, and not the form intself.
    Attached Images Attached Images

  2. #2
    SitePoint Wizard spence_noodle's Avatar
    Join Date
    Jan 2004
    Location
    uk, Leeds (area)
    Posts
    1,264
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    It's a very simple code that Mysql can handle with a small help from PHP.

    PHP Code:
            // if current page number, use it
            // if not, set one!
            
    if(!isset($_GET['page'])){
                
    $page 1;
            } else {
                
    $page $_GET['page'];
            }

            
    // define the number of results per page
            
    $max_results 5;

            
    // figure out the limit for the query based
            // on the current page number.
            
    $from = (($page $max_results) - $max_results);
           
              
            
    // retrive all data from the database
            
    $result mysql_query"SELECT id, details, name, address FROM tablename WHERE id='".$id."' ORDER BY id ASC LIMIT $from$max_results"); 
    The page number must be sent by the address bar with the GET method, in this case. This will help the calculation of data for each page.

    As you can see $max_results has been set to 5, this can be changed to a higher number later on.

    The Mysql query is just an example since your picture has not been approved I cannot see your problem. But it will give you a good idea how to go about writing the script.
    "Don't you just love it when you solve a programming bug only to create another."


Bookmarks

Posting Permissions

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