72 users online (1 members and 71 guests)  


  Results 1 to 9 of 9

Related

  1. Question about SEO and Dynamic Pages    Forum: Search Engine Optimization - SEO - Forum
    Replies: 3
  2. Split categories in half.    Forum: CGI Perl Forum
    Replies: 4
  3. [split] PHP upload script.    Forum: PHP Forum
    Replies: 3
  1. #1
    closer's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2003
    Location
    Amsterdam
    Posts
    4

    Question How to split up dynamic results in multiple pages?

    Hi,
    Before posting this message I have read about 200 pages with information but I am stuck, so I thought to ask the pro guys around if they had any solution to my problem.

    Current situation:

    I have a website with 10000+ pictures divided in 5 categories.
    Each category has 1 page which uses echo to show all images in a specific directory.
    Ofcourse, all images are being displayed on 1 page now I have over 400 images on 1 page and that eats my bandwith... O, I am not using a database!

    What do I want then:
    I want the current situation kept, but with maximum 20 images per page and a <previous 1/2/3...next> navigation bar.

    Here is the code I use:

    function stats() {
    global $titulo,$titulo2,$titulo3,$cstats2,$imagen,$bytes,$fotos,$filas,$cnombres1,$dir,$dir2,$dir3,$dir4;
    $kb = number_format($bytes/1024);
    echo "<table cellspacing=0 cellpadding=4 width=100%>";
    echo "<tr><td align=center width=100% bgcolor=$cstats2 class=titulo>$titulo</td></tr>";
    echo "<table width=100% cellpadding=2 cellspacing=2><tr>";
    $trow = 1;

    array_multisort($fotos["modi"],SORT_DESC,$fotos["nombre"]);
    reset($fotos);
    while (list($key) = each($fotos["nombre"])) {
    echo "<td class=nombre align=center bgcolor=$cnombres1 onmouseover=\"mOver(this);return true\" onmouseout=\"mOut(this);return true\" onclick=\"mClick(this);\"><a href=\"javascript:showFotoset('".$dir2.substr($fotos["nombre"][$key],0,-4).$dir4."')\"><img height=200 src=".$dir.$fotos["nombre"][$key]." border=1></a></td>";
    if ($trow >= $filas) { echo "</tr><tr>"; $trow=1; } else { $trow++; }
    }
    echo "</tr>";

    echo "</table></table>";
    echo "<table><tr ><td align=center width=100% bgcolor=$cstats2 class=titulo><font face=Verdana, Arial, Helvetica, sans-serif size=2>$titulo2</font></td></tr></table>";
    }

    where $dir is the variable i've used to point to the image directory.

    Anyone who could help me with a working version?

  2. #2
    HTML's Avatar
    Administrator

    Status
    Offline
    Join Date
    Aug 2000
    Posts
    3,445

    Follow HTML On Twitter Add HTML on Facebook Add HTML on Google+ Add HTML on Linkedin Visit HTML's Youtube Channel
    Here is a tutorial on pagination http://www.phpfreaks.com/tutorials/43/0.php on the last page of the tutorials you will see a small forum area at the bottom which pertainsto the pagination tutorial, if you have problems be sure to read the posts they may be of help. If you are still stuck I can try to help you here, having just recently done this to our hosting directory and the PHP Scripts directory last month.

    Dave
    AHFBWEB Less customers per server, more power for you!

    Business Class Shared Hosting

  3. #3
    HTML's Avatar
    Administrator

    Status
    Offline
    Join Date
    Aug 2000
    Posts
    3,445

    Follow HTML On Twitter Add HTML on Facebook Add HTML on Google+ Add HTML on Linkedin Visit HTML's Youtube Channel
    Here is a tutorial on pagination http://www.phpfreaks.com/tutorials/43/0.php on the last page of the tutorials you will see a small forum area at the bottom which pertainsto the pagination tutorial, if you have problems be sure to read the posts they may be of help. If you are still stuck I can try to help you here, having just recently done this to our hosting directory and the PHP Scripts directory last month.

    Dave
    AHFBWEB Less customers per server, more power for you!

    Business Class Shared Hosting

  4. #4
    closer's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2003
    Location
    Amsterdam
    Posts
    4
    Thanks dave for the link, I have checked it out and this is where I am so far:
    the problem is I am not using a database and I do not want to with the load of images I already have.

    I am however expereminting with what i have, I've found a way to count the total number of images and put a navigation bar with page numbering.
    BUT
    all images are still displayed on 1 page, they are not divided up into 20 pics per page

    Here's what i do for the navigation:

    function total() {
    $files_directory = "thumbs";
    $new_array = array();
    $files = array();
    $fdirectory = opendir( "$files_directory" );
    while ($file = readdir( $fdirectory ) ) {
    if ( ( $file == "." ) || ( $file == ".." ) ) {
    } else {
    array_push( $files, $file );
    }
    }

    $count = count( $files );
    echo "$count"; // displays total number of images

    $limit = 20;
    if(empty($page)) // Checks if the $page variable is empty (not set)
    $page = 1; // If it is empty, we're on page 1
    $limitvalue = $page * $limit - ($limit);
    if($page != 1){
    $pageprev = $page--;
    // Fancy way of subtracting 1 from $page

    echo("<a href=\"index.php&page=$pageprev\">PREV</a>&nbsp;");

    }else
    echo("PREV&nbsp;");
    // If we're on page 1, PREV is not a link

    $numofpages = $count / $limit;
    for($i = 1; $i <= $numofpages; $i++){
    if($i == $page)
    echo($i."&nbsp;");
    else
    echo("<a href=\"index.php&page=$i\">$i</a>&nbsp;");
    } // This ends the for loop

    if(($count % $limit) != 0){
    if($i == $page)
    echo($i."&nbsp;");
    else
    echo("<a href=\"index.php&page=$i\">$i</a>&nbsp;");
    }

    if(($count - ($limit * $page)) > 0){
    $pagenext = $page++;


    echo("<a href=\"index.php&page=$pageprev\">NEXT</a>");

    }else
    echo("&nbsp; NEXT ".$limit);


    clearstatcache();

    }


    Now i have to integrate it with the code in my first post so also the images will be per 20, and that index.php?page=2 will not give me a 404

    Wow, PHP is heavy for a newbie 8-)

  5. #5
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Hiya.

    because you are not using a database, it means we have to move the 'limiting' of results away from the sql query and into the php.

    best way I can think of is to let the script loop thru every script, but only to display it if the count is between a certain range.

    this would probably be best achieved with a counting variable and a for loop. eg

    PHP Code:
    $i 1;

    // Looping code you already have, but with an $i++ increment WITHIN the loop

    if ($i $start && $i $end) {
    // Echoing code

    hard to follow without proper code in there (dinners burning!) but the jist is that instead of grabbing just the data we need, we instead loop thru ALL the data but only display it if $i count is between $start and $end (these can be passed along in a ?querystring)

    Clear? If not , post away.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  6. #6
    closer's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2003
    Location
    Amsterdam
    Posts
    4
    Aha, eu , nope, cannot work with it (yet)...

    I have been thinking, if you look at the code in my 1st post, you see that I limit the number of table colums with:

    if ($trow >= $filas) { echo "</tr><tr>"; $trow=1; } else { $trow++; }

    where $filas has a value of 4, so the page will show all pictures in a table with 4 colums and as many rows as it needs.

    Well, if I know that the total amount of pictures i want to show on 1 page is 20, can't I also say when 5 rows are reached, cut page, put a navigation below?

    Just trying...

    Another thing that could work is using array_slice according to PHP.net but there are to few examples for me to fully understand this function... will be reading more, meanwhile, all comments are welcome

  7. #7
    Doorknob's Avatar
    Super Newbie

    Status
    Offline
    Join Date
    Jun 2002
    Location
    Malaysia
    Posts
    316
    i dont know anything about php, so please ignore this post if it's irrelavent. how bout using querystrings?

    pass on the value of the page, then use the page number to find out what images need to be displayed.

    for instance, if u want 20 images per page, then if u pass on the value of the page to be viewed, i.e. page 3, then u can calculate that images 41-60 need to be displayed.

    firstImage = ((pageno-1) * 20) + 1
    lastImage = firstImage + 19

    then just loop through the images

    this is assuming you've named all images = image1.jpg, image2.gif...

    if not u can put all the file names into an array, and loop through it and take out array item number 41-60, only displaying the needed images

    total pages to be displayed = (number of files in array / 20) + 1

    if u want your page to display 10 pages at a time, then that takes more work

    hope that helps

    (i'm an asp programmer, so this might not apply to php)

  8. #8
    closer's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2003
    Location
    Amsterdam
    Posts
    4
    Well, I finally decided to switch to a database, much more effecient and flexible

    Thanks for all responses!

  9. #9
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Excellent. DB's are the way to go
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?



Tags for this Thread