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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post

    Thumbs up [RESOLVEd] Paginate a result

    Good day to you,
    I need to paginate the result of this code :

    PHP Code:

    <?php
    $image_counter 
    = -1;
    $row_counter 0;
    $cell_counter 0;
    $show=array('.jpg','.JPG','.gif','.GIF');

    $val$_GET['folder'];
    $val1 $_GET['folder'];
    $val0 $val1;
    $val.="/"

    $path "$val";
    $path2 str_replace("Pic-S""Pic-B"$val);
    $dirshort substr($val,20);
    $dirshort0 $val1;

    $comicon "http://ponder.peuplies.info/V_0-1/Muraille/Change-comment-icon/comment_icon_change.txt";
    $fh1 fopen($comicon'r');
    $outputt1 fgets($fh1);
    $output1 str_replace("../..""http://ponder.peuplies.info/V_0-1"$outputt1 );
    fclose($fh1);




    $dir_handle = @opendir($path) or die("Unable to open $path");
    $image_table "<table valign=\"top\" align=\"center\" width=\"100%\">\n";
    $image_table .= "\n<tr><td bgcolor=\"#cccccc\" align=\"center\" colspan=\"3\"><table valign=\"top\" align=\"center\" width=\"100%\" border=\"0\" cellspacing=\"0\">\n";
    $image_table .= "\n<tr><td bgcolor=\"#000033\" class=\" white00\" align=\"left\"><b class=\"white00\">Photos in - Photos dans :</b> $dirshort</td>";
    $image_table .= "\n    <td bgcolor=\"#000033\" align=\"right\" ><br></td></tr>\n";
    $image_table .= "\n<tr><td bgcolor=\"#cccccc\" class=\" white00\" align=\"right\" colspan=\"2\">\n";
    $image_table .= "<script type=\"text/javascript\">ajaxinclude(\"http://ponder.peuplies.info/V_0-1/Muraille/Change-shoppingcart-button/change_shoppingcart_button.txt\")</script>";
    $image_table .= "\n</td></tr>\n";
    $image_table .= "\n</table><tr>\n";
    while (
    false !== ($file readdir($dir_handle))) {
      if(
    in_array(substr($file,-4,4),$show)){
            if(!((
    $image_counter 1) % 3)){
              
    $row_counter++;
            }


    $newpath0 substr($file,0,-4);
    $newpath00 substr($file,0,-4);

          
    $image_table .=(($image_counter 1) % 3)? "" "</tr>\n<tr><td><br></td></tr><tr valign=\"top\">";
          
    $image_table .= "\n<td valign=\"top\" width=\"180\"><table width=\"180\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\" align=\"center\">\n";
          
    $image_table .= "\n<tr><td valign=\"top\" bgcolor=\"#ffff00\" width=\"180\"><table width=\"180\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\" align=\"center\">\n";
          
    $image_table .= "\n<tr><td valign=\"top\" bgcolor=\"#003366\" width=\"180\"><table width=\"180\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\" align=\"center\">\n";
          
    $image_table .= "\n<tr><td bgcolor=\"#000033\" align=\"center\"width=\"180\"><b>$newpath0</b></td></tr>\n";
          
    $image_table .= "\n<tr><td bgcolor=\"#000000\" width=\"180\"><a href='http://ponder.peuplies.info/V_0-1/Art/$path2$file' target='_blank' rel=\"thumbnail\"><img src=\"http://ponder.peuplies.info/V_0-1/Art/$path$file\" width=\"180\" border=\"0\"></a></td></tr>\n";
          
    $image_table .= "\n<tr><td bgcolor=\"#000033\" align=\"center\" width=\"180\"><IMG SRC=\"http://ponder.peuplies.info/V_0-1/Art/minus.gif\" CLASS=\"showstate\" ONCLICK=\"expandcontent(this, 'sc".$newpath0."')\" align=\"right\"><b>Information</b></td></tr>\n";
          
    $image_table .= "\n</table>\n";
          
    $image_table .= "\n<div id=\"sc".$newpath0."\" class=\"switchcontent\" width=\"180\">\n";
          
    $image_table .= "\n<table border=0 align=center cellspacing=0 cellpading=0 width=\"180\">\n";
          
    $image_table .= "\n<tr><td bgcolor=\"#ffffff\" align=\"left\" class=\"black0\" width=\"180\"><b class=\"black0\" width=\"180\">Description :<br></b><script type=\"text/javascript\">ajaxinclude(\"http://ponder.peuplies.info/V_0-1/Art/Pictures/Pics/Commentaires/$newpath0.txt\")</script></td></tr>\n";
          
    $image_table .= "\n<tr><td bgcolor=\"#ffffff\" align=\"left\" class=\"black0\" width=\"180\"><br></td></tr>\n";
          
    $image_table .= "\n<tr><td valign=\"top\" bgcolor=\"#ffffff\" width=\"180\"><table width=\"180\" border=\"0\" cellpadding=\"1\" cellspacing=\"0\" align=\"center\">\n";
          
    $image_table .= "<tr><td bgcolor=\"#ffffff\" align=\"left\" width=\"180\" valign=\"top\"><a href=\"http://ponder.peuplies.info/V_0-1/Art/rater0.php?var1=$newpath0&var00=$path$file\" target=\"autre\" title=\"Rate it! - Noter la !\" alt=\"Rate it!\" class=\"black000\"><script type=\"text/javascript\">ajaxinclude(\"http://ponder.peuplies.info/V_0-1/Art/rater1.php?var1=$newpath0&var00=$path$file\")</script></a></td>";
          
    $image_table .= "\n<td bgcolor=\"#ffffff\" align=\"center\" class=\"black0\" width=\"180\" colspan=\"2\"><script type=\"text/javascript\">ajaxinclude(\"http://ponder.peuplies.info/V_0-1/Art/Pictures/Pics/Prix/$newpath0.txt\")</script><script type=\"text/javascript\">ajaxinclude(\"http://ponder.peuplies.info/V_0-1/Art/Pictures/Pics/Vente/$newpath0.txt\")</script></td></tr>\n";
          
    $image_table .= "\n</table>\n";
          
    $image_table .= "\n<tr><td valign=\"top\" bgcolor=\"#ffffff\" width=\"180\"><table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\" align=\"center\">\n";
          
    $image_table .= "\n<tr><td bgcolor=\"#ffffff\" align=\"left\" width=\"180\"><a href=\"http://ponder.peuplies.info/V_0-1/Art/commentaires.php?var001=$newpath0&var002=$path$file\" target=\"autre\" title=\"Add comments - Ajout de commentaires.\" alt=\"Add comments - Ajout de commentaires\" class=\"white000\"><img src=\"".$output1."\" border=\"0\"></a></td>";
          
    $image_table .= "</td></tr>\n";
          
    $image_table .= "\n</table>\n";
          
    $image_table .= "\n</div>\n";
          
    $image_table .= "\n</table>\n";
          
    $image_table .= "\n</table>\n";
          
    $image_table .= "\n</table></td>\n\n\n";

          ++
    $image_counter;
          ++
    $cell_counter;
      }
    }
    $colspan= ($row_counter 3) - $cell_counter;
    $image_table .= ($cell_counter 3) ?  "<td colspan=$colspan valign=top>&nbsp;</td>" "";
    $image_table .= "</tr>\n</table>\n";
    echo 
    "$image_table<br><br>";

    ?>


    This code read a given directory and output image with info formated in rows of 3.

    Now I need that the code after 4 row would create a link to go to the nexts images.

    Thanks !
    Last edited by Peuplarchie; 11-12-2007 at 06:59 AM.

  • #2
    New Coder
    Join Date
    Aug 2007
    Posts
    53
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Quick question, What's the /n used for. I've never used it and have been wondering what it is.

  • #3
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    http://www.petefreitag.com/cheatsheets/ascii-codes/

    \n = New Line
    \r = cariage retur or something like that.

  • Users who have thanked Peuplarchie for this post:

    JustBlaze (11-12-2007)

  • #4
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    sometime it work very well.....

  • #5
    New Coder
    Join Date
    Aug 2007
    Posts
    53
    Thanks
    11
    Thanked 2 Times in 2 Posts
    so it makes the source look better in a browser?

  • #6
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Quote Originally Posted by JustBlaze View Post
    so it makes the source look better in a browser?
    Yes, or you can use it in file/text output to split things to new lines.

  • Users who have thanked Inigoesdr for this post:

    JustBlaze (11-12-2007)

  • #7
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    No it don't work, I playing with directory images listing .
    Variable are set vor a variable directory

  • #8
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Quote Originally Posted by Peuplarchie View Post
    No it don't work, I playing with directory images listing .
    Variable are set vor a variable directory
    ... what?
    All you need to do pagination is the total number of files in the directory, the number of items per page, and the current page(if any). To find out the number of files in the directory look at the examples in the manual.

    Here is some example code I have that prints a pagination string:
    PHP Code:
    /**
     * paginate - This function uses the $_GET['page'] variable to pass the page number to the next/prev page
     *
     * @param int $currentPage Current Page
     * @param int $totalPages Total Pages
     * @param string $link Hyperlink with a ? at the end if it doesn't have any $_GET vars
     *
     * @return string
     */
    function paginate($currentPage$totalPages$link)
    {
        
    $prev $pages $next '';
        
        if(
    $currentPage == 0)
            
    $currentPage 1;    
        elseif(
    $currentPage 1)
            
    $prev sprintf('<a href="%s&page=%d">&laquo; Previous</a> '$link$currentPage 1);
        
        for (
    $i 1$i <= $totalPages$i++)
        {
            if(
    $currentPage == $i)
                
    $pages .= $i ' ';
            else
                
    $pages .= sprintf('<a href="%s&page=%d">%d</a> '$link$i$i);
        }
        
        if(
    $currentPage $totalPages)
            
    $next sprintf('<a href="%s&page=%d">Next &raquo;</a>'$link$currentPage 1);

        return 
    $prev $pages $next;
    }
    // example:
    echo paginate((int) $_GET['page'], 10$_SERVER['SCRIPT_NAME'] . '?'); 
    So all you need to do is count the files, and replace the 10 with it.
    Last edited by Inigoesdr; 11-12-2007 at 06:55 AM. Reason: Added pagination function


  •  

    Posting Permissions

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