The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Pagination with link to changing image ID.
Baggy
post Feb 24 2009, 01:14 PM
Post #1





Group: Members
Posts: 2
Joined: 22-June 08
Member No.: 5,958



Hello, I am fairly new to php. I am trying to take multiple .gif images from a directory, and display them, 10 per page, with pagination. I want page number links like those on Digg or Youtube (i.e. 1 2 3 4 5...11). I also want each image displayed to link to a new page displaying the corresponding code for a user to use that image (i.e. a text area with <img src="http://image(x).gif">), without having to create multiple new pages for each individual image code. I am looking for something similar to THIS. Each image in the directory is named graphic1.gif, graphic2.gif, graphic(x).gif etc etc.

So far i have this:

CODE

<? 

function dirList ($directory)  


    
// create an array to hold directory list 
    
$results = array(); 

    
// create a handler for the directory 
    
$handler opendir($directory); 

    
// keep going until all files in directory have been read 
    
while ($file readdir($handler)) { 

        
// if $file isn't this directory or its parent,  
        // add it to the results array 
        
if ($file != '.' && $file != '..'
            
$results[] = $file
    } 

    
// tidy up: close the handler 
    
closedir($handler); 

    
// done! 
    
return $results



function 
file_extension($filename

    
$path_info pathinfo($filename); 
    return 
$path_info['extension']; 


$totalresults dirList('animations'); 

$alength sizeof($totalresults); 


$gifresults = array(); 

for(
$i=0$i<$alength$i++){ 
    if(
file_extension($totalresults[$i]) == "gif"){ 
        
$gifresults[] = $totalresults[$i]; 
    } 


$number_per_page 10

$pages ceil(sizeof($gifresults) / $number_per_page); 

$current_page $_GET['p']; 

for(
$i=0$i<$number_per_page$i++){ 
    
$x = ($current_page $number_per_page)+$i
    echo 
"<img src=\"/graphics/animations/" $gifresults[$x] . "\" />" "<br />"


echo 
"<a href=\"?p=".($current_page-1)."\">Previous</a> | <a href=\"?p=".($current_page+1)."\">Next</a>"

?> 


Any help is much appreciated.

Thanks.

B.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Darin McGrew
post Feb 24 2009, 04:23 PM
Post #2


WDG Member
********

Group: Root Admin
Posts: 8,365
Joined: 4-August 06
From: Mountain View, CA
Member No.: 3



QUOTE
I also want each image displayed to link to a new page displaying the corresponding code for a user to use that image (i.e. a text area with <img src="http://image(x).gif">), without having to create multiple new pages for each individual image code.
How do you want to create these individual image pages? You could create a separate PHP program that displays an individual image page, or you could pass a new parameter to this PHP program to tell it whether to display the index page or an individual image page.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 24th April 2024 - 12:32 AM