Page nav extention needed.

Discussion in 'PHP' started by sittsait, Aug 19, 2008.

  1. #1
    Hi guys, ive got this great script mixed up that displays all .swf files in dir and shows em as images. Now that there are more and more .swf files, id like to but em into pages. So after every 30 images or so, it would add the next 30 with link (ex. page 2) under the script.

    Is this even possible? Hard to achieve?

    The script itself comes below:

    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "DTD/xhtml1-transitional.dtd">
    <html>
    <head>
       <title>Segakaust</title>
    <link href="***/infusions/flash_game_system/popup/gb_styles.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
        var GB_ROOT_DIR = "http://***/infusions/flash_game_system/popup/";
    </script>
    </head>
    <body>
    <script type="text/javascript" src="http://***infusions/flash_game_system/popup/AJS.js"></script>
    <script type="text/javascript" src="http://***/infusions/flash_game_system/popup/AJS_fx.js"></script>
    <script type="text/javascript" src="http://***/infusions/flash_game_system/popup/gb_scripts.js"></script>
    <?php
    require_once "../../../maincore.php";
    if (iGUEST) {
    echo "<script language='Javascript'>";
    echo "<!--
    alert ('Sisselogides või registreerudes on sul võimalik flashmängudega punkte koguda.')
    //-->";
    echo "</script>";
    }else{
    echo "";
    }
    
    $columns     = 5;
    $thmb_width  = 130;
    $thmb_height = 90;
    
    function resizeImage($originalImage,$toWidth,$toHeight){
        
        // Get the original geometry and calculate scales
        list($width, $height) = getimagesize($originalImage);
        $xscale=$width/$toWidth;
        $yscale=$height/$toHeight;
        
        // Recalculate new size with default ratio
        if ($yscale>$xscale){
            $new_width = round($width * (1/$yscale));
            $new_height = round($height * (1/$yscale));
        }
        else {
            $new_width = round($width * (1/$xscale));
            $new_height = round($height * (1/$xscale));
        }
        // Resize the original image
        $imageResized = imagecreatetruecolor($new_width, $new_height);
        $imageTmp     = imagecreatefromjpeg ($originalImage);
        imagecopyresampled($imageResized, $imageTmp, 0, 0, 0, 0, 
                           $new_width, $new_height, $width, $height);
    
        return $imageResized;
    } 
    
    function generateThumbnails(){
        global $thmb_width,$thmb_height;
        
        // Open the actual directory
        if ($handle = opendir("")) {
            // Read all file from the actual directory
            while ($file = readdir($handle))  {
                // Check whether tha actual item is a valid file
                if (is_file($file)){
                          // Check if the actual file is a jpeg image
                          if (($extName == '.jpg') || ($extName == '.jpeg')){
                            $thmbFile = $dirName.'/'.$fileMain.'.jpg';
                            // If a thumbnail dosn't exists tahn create a new one
                            if (!file_exists($thmbFile)){
                                imagejpeg(resizeImage($file,$thmb_width,$thmb_height)
                                         ,$thmbFile,80);
                            }
                        }
                      } 
                   }
               }
        }
    
    function getNormalImage($file){
        $base = substr($file,0,strrpos($file,'.jpg'));
        if (file_exists($base.'.jpg')) return $base.'.swf';
        if (file_exists($base.'.gif')) return $base.'.swf';
        if (file_exists($base.'.png')) return $base.'.swf';
        elseif (file_exists($base.'.jpeg')) return $base.'.swf';
        else return "";
    }
    
    function displayPhotos(){
        global $columns;
        
        generateThumbnails();
        $act = 0;
        // Open the actual directory
        if ($handle = opendir(".")) {
            // Read all file from the actual directory
            while ($file = readdir($handle))  {
                // Check whether tha actual item is a valid file
                if (is_file($file)){
                    // Check whether the actual image is a thumbnail
                      if (strpos($file,'.jpg')){
                        ++$act;
                        if ($act > $columns) {
                            echo '</tr><tr>
                               <td class="photo"><a href="'.getNormalImage($file).'" rel="gb_page_center[600, 573]">
                                   <img src="'.$file.'" width="134" height="114" onContextMenu="return false;" border="0"/></a></td>';    
                            $act = 1;
                        } else {
                            echo '<td class="photo"><a href="'.getNormalImage($file).'" rel="gb_page_center[600, 573]">
                               <img src="'.$file.'" width="134" height="114" onContextMenu="return false;" border="0"/></a></td>';    
                        }
                          
                      }
                  }
            }
        }    
    }
    
    ?>
      <table align="center"><tr>     
        <?php displayPhotos(); ?>
      </table>     
    </body>   
    
    Code (markup):
    Its not the best code, but it works. IF you can help me, id REALLY- REALLY appreciate it. :)
     
    sittsait, Aug 19, 2008 IP
  2. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #2
    What you are looking for is called 'pagination'. Google it.
     
    rohan_shenoy, Aug 19, 2008 IP