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.

It’s a very simple code that Mysql can handle with a small help from PHP.

   
        // 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.