Results 1 to 2 of 2

Thread: Looking For Some Help With Pagination.

  1. #1
    Join Date
    Apr 2009
    Posts
    59

    Looking For Some Help With Pagination.

    I've been reading through some tutorials on pagination, and I'm trying to implement it into a current project, but I'm not having the best luck with it. I already have some PHP pulling info from a database and everything how I'd like, so that's all set, but I'm not sure how to implement that into some PHP for pagination.

    The PHP I have right now that I'd like to paginate is this:

    PHP Code:

                        <?PHP
            
                            $user_name 
    "####";
                            
    $password "####";
                            
    $database "####";
                            
    $server "####";
                        
                        
    $db_handle mysql_connect($server$user_name$password);
                        
    $db_found mysql_select_db($database$db_handle);
                        
                
    ?>
            <div id="listing_top"></div>
                <div id="listings">
        
                <?PHP
                                                            
                            
    if ($db_found) {
                            
                            
    $SQL "SELECT * FROM tbl_rest_list ORDER BY Name";
                            
    $result mysql_query($SQL);

                                while (
    $db_field mysql_fetch_array($result)) {
            
                                if(!empty(
    $db_field['url'])) {
                                    echo 
    '<div class="name">' "<h3>" $html '<a href="' $db_field['url'] . '">' $db_field['Name'] . '</a>' "<h3>" "</div>";
                                }
                                else {
                                    echo 
    "<div>" "<h3>" $html $db_field['Name'] . "<h3>" "</div>";
                                }
                            
                                echo 
    "<div>" $db_field['Street'] . "</div>";
        
                                echo 
    "<div>" $db_field['City'] . ", " $db_field['State'] . "</div>";
            
                                echo 
    "<div>" "<em>Phone: </em>" "<strong>" $db_field['Phone'] . "</strong>" "</div>";
            
                                echo 
    "<div>" $db_field['Email'] . "</div>";
        
                                echo 
    '<div id="type">' "<em>Type of Food: </em>" $db_field['Type'] . '</div>';
                        }
                        
    mysql_close($db_handle);
                                
                        }
                        else {
                        echo 
    "Database NOT Found ";
                        
    mysql_close($db_handle);
                        }
                                
    ?>

                </div>

            <div id="listing_bottom"></div>
    Thanks in advance for any help. You guys have already helped me a ton in understanding PHP. I really appreciate it.
    Last edited by Alan; 01 Nov 2009 at 02:31 PM. Reason: changed bb code (use PHP bb code tags for syntax highlighting)

  2. #2
    Join Date
    Oct 2009
    Location
    Charleston, SC
    Posts
    48
    I'm assuming that you have some sort of list that you'd like to page. The following query is what I use to do paging...

    Code:
    $displayNumber = 20;
    $lowerBound = ($page_number - 1) * $displayNumber;
    $sql = "select * from table_name limit $lowerBound, $displayNumber";
    You'll need to set a page variable and increment/decrement this variable as you go from page to page. Then in your php you capture the page number and the code does the rest.

    **note - $displayNumber = the number of items to show in your list.

Posting Permissions

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