Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2009
    Posts
    90
    Thanks
    5
    Thanked 0 Times in 0 Posts

    help with adding pagination to existing php

    Hello I have this existing php that will look in a directory then get the files and display the links along with a downloads counter per file, but as you can imagine the page is getting quite long, I have found a pagination php script that looks good, but im stuck on adding it into my existing php,

    heres my current set up

    PHP Code:
    <?php

    // Error reporting:
    error_reporting(E_ALL^E_NOTICE);

    // Including the DB connection file:
    require 'connect.php';

    $extension='';
    $files_array = array();


    /* Opening the thumbnail directory and looping through all the thumbs: */

    $dir_handle = @opendir($directory) or die("There is an error with your file directory!");

    while (
    $file readdir($dir_handle)) 
    {
        
    /* Skipping the system files: */
        
    if($file{0}=='.') continue;
        
        
    /* end() returns the last element of the array generated by the explode() function: */
        
    $extension strtolower(end(explode('.',$file)));
        
        
    /* Skipping the php files: */
        
    if($extension == 'php') continue;

        
    $files_array[]=$file;
    }

    /* Sorting the files alphabetically */
    sort($files_array,SORT_STRING);

    $file_downloads=array();

    $result mysql_query("SELECT * FROM download_manager");

    if(
    mysql_num_rows($result))
    while(
    $row=mysql_fetch_assoc($result))
    {
        
    /*  The key of the $file_downloads array will be the name of the file,
            and will contain the number of downloads: */
            
        
    $file_downloads[$row['filename']]=$row['downloads'];
    }

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>PHP &amp; MySQL File Download Counter | Tutorialzine demo</title>

    <link rel="stylesheet" type="text/css" href="styles.css" />
    <link rel="stylesheet" type="text/css" href="fancybox/jquery.fancybox-1.2.6.css" media="screen" />

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script type="text/javascript" src="script.js"></script>

    </head>

    <body>


        
    <div id="file-manager">

        <ul class="manager">
        <?php 

            
    foreach($files_array as $key=>$val)
            {
                echo 
    '<li><a href="download.php?file='.urlencode($val).'">'.$val.
                        <span class="download-count" title="Times Downloaded">'
    .(int)$file_downloads[$val].'</span> <span class="download-label">download</span></a>
                        </li>'
    ;
            }
        
        
    ?>
      </ul>

    </div>





    </body>
    </html>


    And heres the pagination i wish to put in

    PHP Code:
    <?php
      
        
    /************************************************************\
        *
        *     PHP Array Pagination Copyright 2007 - Derek Harvey
        *     www.lotsofcode.com
        *
        *     This file is part of PHP Array Pagination .
        *
        *     PHP Array Pagination is free software; you can redistribute it and/or modify
        *     it under the terms of the GNU General Public License as published by
        *     the Free Software Foundation; either version 2 of the License, or
        *     (at your option) any later version.
        *
        *     PHP Array Pagination is distributed in the hope that it will be useful,
        *     but WITHOUT ANY WARRANTY; without even the implied warranty of
        *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        *     GNU General Public License for more details.
        *
        *     You should have received a copy of the GNU General Public License
        *     along with PHP Array Pagination ; if not, write to the Free Software
        *     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        *
        \************************************************************/
        
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
      <meta http-equiv="content-type" content="text/html; charset=windows-1250">
      <title>PHP Array Pagination</title>
      <style>
      <!--
       body {
        font-family: Tahoma, Verdana, Arial, Sans-serif;
        font-size: 11px;
       }
       hr {
        border: 1px #ccc;
        border-style: none none solid none;
        margin: 20px 0;
       }
       a {
        color: #333;
        text-decoration: none;
       }
       a:hover {
        text-decoration: underline;
       }
       a.selected {
        font-weight: bold;
        text-decoration: underline;
       }
       .numbers {
        line-height: 20px;
        word-spacing: 4px;
       }
      //-->
      </style>






      </head>
      <body>
        <h1>PHP Array Pagination</h1>
        <hr  />
          <?php
            
    // Include the pagination class
            
    include 'pagination.class.php';
            
    // Create the pagination object
            
    $pagination = new pagination;
            
            
    // some example data
            
    foreach (range(1100) as $value) {
              
    $products[] =  foreach($files_array as $key=>$val)
            }
            
            
    // If we have an array with items
            
    if (count($products)) {
              
    // Parse through the pagination class
              
    $productPages $pagination->generate($products10);
              
    // If we have items 
              
    if (count($productPages) != 0) {
                
    // Create the page numbers
                
    echo $pageNumbers '<div class="numbers">'.$pagination->links().'</div>';
                
    // Loop through all the items in the array
                
    foreach ($productPages as $productArray) {
                  
    // Show the information about the item
                  
    echo '<p><b>'.urlencode($val).'">'.$val.'</b> &nbsp; &pound;'.(int)$file_downloads[$val].'</p>';
                }
                
    // print out the page numbers beneath the results
                
    echo $pageNumbers;
              }
            }
          
    ?>
          <hr />
          <p><a href="http://www.lotsofcode.com/php/projects/php-array-pagination" target="_blank">PHP Array Pagination</a> provided by <a href="http://www.lotsofcode.com/" target="_blank">Lots of Code</a></p>
      </body>
    </html>

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,539
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    If your database contains the filenames and number of downloads,
    why do you need to open the directory and load the names of the files?

    I would think you only need to work with the database, not the directory.

    What am I not seeing here?


  •  

    Posting Permissions

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