#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    56
    Rep Power
    2

    Paginating Your Data with AJAX and Awesome PHP Pagination Class


    Hi,

    I am trying to implement a pagination script called Paginating Your Data with AJAX and Awesome PHP Pagination Class for navigating through a gallery of images but when I set more than eight records per page the images appear to go beyond the browser horizontally in a single infinity row instead of starting a new row below the first row.

    I want the number of records (images) per page to be 16 arranged in two rows(eight images in the upper row and 8 images in the bottom row).

    Please, help. Here is my code:

    PHP Code:
    <?php

    //query all data anyway you want
    $sql "select * from collections ORDER BY c_id ASC";

    //now, where gonna use our pagination class
    //this is a significant part of our pagination
    //i will explain the PS_Pagination parameters
    //$conn is a variable from our config_open_db.php
    //$sql is our sql statement above
    //8 is the number of records retrieved per page
    //4 is the number of page numbers rendered below
    //null - i used null since in dont have any other
    //parameters to pass (i.e. param1=valu1&param2=value2)
    //you can use this if you're gonna use this class for search
    //results since you will have to pass search keywords
    $pager = new PS_Pagination$mysqli$sql164null );

    //our pagination class will render new
    //recordset (search results now are limited
    //for pagination)

    $rs $pager->paginate(); 

    //get retrieved rows to check if
    //there are retrieved data
    $num $rs->num_rows;

    if(
    $num >= ){
        
    //creating our table header
        //looping through the records retrieved
        
    while( $row $rs->fetch_assoc() ){
        echo 
    "<td valign=top>\n
        
        <table width=150 border=1 align=left class=allborder> \n
        <tr> \n
        <td width=70>
    $row[ctitle]</td> \n
        </tr>\n
        
        <tr> \n
            <td><img src=\"./images/
    {$row['cfilename']}\" width=\"90\" height=\"120\" alt=\"\" /></a> \n
            </td>
        </tr>\n
            
        </table>\n</td>\n
         "
    ;    
        }  
        {     
        echo 
    "</tr>\n<tr>\n<td colspn=2>&nbsp; \n";
                                                            
        }                                                
        echo 
    "</table>";
        }
        else{
        
    //if no records found
            
    echo "No records found!";
        }

    ?>

    I did not have this problem with other mysql pagination codes I used before. It's now that I have re-written my code in mysqli and i need this pagination.

    Joseph
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2012
    Posts
    119
    Rep Power
    32
    You have nothing in your while loop to count how many images have been displayed so far and then create a new row if on the 4th image, hence why you are just getting one long row of 16 images.

    Below is what you need to do but I have separated the PHP and HTML as I just can't work efficiently with code the way you have it and it is much easier to change and debug when separated.

    PHP Code:
    if($num >= 1 ) { 
        //creating our table header 
    ?>
    <table>
    <tr>
    <?php
        
    //looping through the records retrieved 
        
    $count 0;
        while( 
    $row $rs->fetch_assoc() ){ ?>

       <td valign=top>
         
        <table width=150 border=1 align=left class=allborder> 
        <tr> 
        <td width=70><?php echo $row[ctitle]; ?></td>
        </tr>
         
        <tr> 
            <td><img src="./images/<?php echo $row['cfilename']; ?>" width="90" height="120" alt="" /></a>
            </td> 
        </tr> 
             
        </table>
    </td>
    <?php $count++; 
      if (
    $count %== && $count $num) {
    ?>
    </tr><tr>
    <?php 
    }  
    ?>
    </tr>
    </table> 
    <?php ?>

    Comments on this post

    • josephbupe agrees : It work ! Thank youso much. Stay well.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    56
    Rep Power
    2
    Hi simplypixie,

    Your solution worked a charm. Thank you so much.

    Stay well.

    joseph

IMN logo majestic logo threadwatch logo seochat tools logo