Page 1 of 1

paging problem for my gallery

Posted: Wed Feb 15, 2006 9:10 am
by gamesnthings
Hello every one

I have a gallery page where i only display 6 thumbnails per page.

I have been able to modify the code so that only 6 results are shown with their caption but can get a code for paging.

(1)what do i need to add to my code so that i get a previous or next link.

(2) If u look at my code, if i click on a thumb nail it opens a big pic with caption on the same page. How can i modify it to open in another page.

any help will be appreicated.

thanks

Code: Select all

<?php 
    include("conn.php"); 


    // initialization 
    $result_array = array(); 
    $counter = 0; 
$images_dir = "photos"; 
$Start = 0; 
$ByPage = 6; 

    $cid = (int)($_GET['cid']); 
    $pid = (int)($_GET['pid']); 



    // Thumbnail Listing 

    { 
        $number_of_thumbs_in_row = 2; 
                     
        $result = mysql_query( "SELECT photo_id,photo_caption,photo_filename FROM gallery_photos $MyQuery $MyOrder limit $Start, $ByPage "); 
        $nr = mysql_num_rows( $result ); 

        if( empty( $nr ) ) 
        { 
            $result_final = "\t<tr><td>No Images found</td></tr>\n"; 
        } 
        else 
        { 
            while( $row = mysql_fetch_array( $result ) ) 
            { 
                $result_array[] = "<a href='viewgallery.php?cid=$cid&pid=".$row[0]."'><img src='".$images_dir."/tb_".$row[2]."' border='0' alt='".$row[1]."' /><br />".$row[1]."</a>"; 


            } 
            mysql_free_result( $result );     

            $result_final = "<tr>\n"; 
     
            foreach($result_array as $thumbnail_link) 
            { 
                if($counter == $number_of_thumbs_in_row) 
                {     
                    $counter = 1; 
                    $result_final .= "\n</tr>\n<tr>\n"; 
                } 
                else 
                $counter++; 

                $result_final .= "\t<td>".$thumbnail_link."</td>\n"; 
            } 
     
            if($counter) 
            { 
                if($number_of_photos_in_row-$counter) 
            $result_final .= "\t<td colspan='".($number_of_photos_in_row-$counter)."'>&nbsp;</td>\n"; 

                $result_final .= "</tr>"; 
            } 
        } 
    } 

    // Full Size View of Photo 
    if( $pid ) 
    { 
        $result = mysql_query( "SELECT photo_caption,photo_filename FROM gallery_photos WHERE photo_id='".addslashes($pid)."'" ); 
        list($photo_caption, $photo_filename) = mysql_fetch_array( $result ); 
        $nr = mysql_num_rows( $result ); 
        mysql_free_result( $result );     

        if( empty( $nr ) ) 
        { 
            $result_final = "\t<tr><td>No Photo found</td></tr>\n"; 
        } 
        else 
        { 

            $result_final .= "<tr>\n\t<td align='center'> 
                    <br /> 
                    <img src='".$images_dir."/".$photo_filename."' border='0' alt='".$photo_caption."' /> 
                    <br /> 
                    $photo_caption 
                    </td> 
                    </tr>"; 
        } 
    } 

// Final Output 
echo <<<__HTML_END 

<html> 
<head> 
    <title>Gallery View</title> 
</head> 
<body> 
<table width='100%' border='0' align='center' style='width: 100%;'> 
$result_final         
</table> 
</body> 
</html> 

__HTML_END; 
?>  
        
gamesnthings 
View Public Profile 
Send a private message to gamesnthings 
Find More Posts by gamesnthings 
Add gamesnthings to Your Buddy List

Posted: Wed Feb 15, 2006 9:19 am
by yum-jelly
Just use target='_blank' in your <a> tag!

Code: Select all

$result_array[] = "<a href='viewgallery.php?cid=$cid&pid=".$row[0]."' target='_blank'><img src='".$images_dir."/tb_".$row[2]."' border='0' alt='".$row[1]."' /><br />".$row[1]."</a>";

yj!

Posted: Wed Feb 15, 2006 9:28 am
by gamesnthings
thanks for helping mate,
but that didnt really help much. all it did was create the same page in the new window.

Posted: Wed Feb 15, 2006 9:55 am
by pickle
Doing a search for Pagination will probably get you the answers you need.