www.webdeveloper.com
Results 1 to 3 of 3

Thread: Pagination [ Creating pages for listings in a table ] - Please help

Hybrid View

  1. #1
    Join Date
    Apr 2014
    Posts
    14

    Pagination [ Creating pages for listings in a table ] - Please help

    Resources used while trying to implement it on my own:

    - http://www.phpfreaks.com/tutorial/basic-pagination
    - http://www.youtube.com/watch?v=bY2L_F9SIqQ

    This is how my tables are generated
    Code:
        $results = mysql_query($testquery) or die (mysql_error());
        	
        	while($row = mysql_fetch_array($results)) 
        	{
        		echo "<tr>";
        		echo "<td align='center'>". $tempDate . " </td>";
        		echo "<td align='center'>$". number_format($row[0], 2) . "</td>";
        		echo "<td align='center'>". $row[1] . "</td>";
        		echo "<td align='center'>". $row[2] . "</td>";
        		echo "</tr>";
        	}
    I don't get it... I'm so confused. Can someone please help me implement this? My page is setup so my table should have 16 rows at any given time, anything more than that looks horrible. So I want to create pages.

  2. #2
    Join Date
    May 2014
    Posts
    3
    I didn't watch or read the articles you linked to, but if > 16 pages is the problem, break out of the loop.

    Code:
        $num = 0;
        while($row = mysql_fetch_array($results)) { 
            $num++;
            ....
            ....
            if($num > 16) { 
                break;
            }
        }
    Or you can limit the quest results to 17 (assuming 1 per page).
    Code:
        $query = mysql_query("...... LIMIT 17");
        if(mysql_num_rows($results) == 17) {
            // We now know that there are more than 16 rows. This prevents the entire table from being queried and only gets the first 17 results then quits. 
        }

  3. #3
    Join Date
    Apr 2014
    Posts
    14
    Quote Originally Posted by KalobTaulien View Post
    I didn't watch or read the articles you linked to, but if > 16 pages is the problem, break out of the loop.

    Code:
        $num = 0;
        while($row = mysql_fetch_array($results)) { 
            $num++;
            ....
            ....
            if($num > 16) { 
                break;
            }
        }
    Or you can limit the quest results to 17 (assuming 1 per page).
    Code:
        $query = mysql_query("...... LIMIT 17");
        if(mysql_num_rows($results) == 17) {
            // We now know that there are more than 16 rows. This prevents the entire table from being queried and only gets the first 17 results then quits. 
        }
    I don't want to limit the results, I want to create multiple pages for the results in my table. My application is supposed to display all recent history of logs that are stored in a database, only showing 16 of them would ruin the purpose, which is why I need to create multiple pages.

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