Jump to content

Page numbering


Woodburn2006

Recommended Posts

i am creating a photo gallery and i want to only display a few images as thumbnails at a time so that users click these thumbnails and they view the large image. when the gallery has more images i want to display the photos 5 at a time with page numbers so users can flick through the pages. i have done this before but cannot work out why i cannot get it to work this time. this is the code i am using for this section of this page:

 

<?
    if(empty($page)){$page = 1;}

$limit= 5;                
    $query_count = "SELECT count(*) AS rowcount FROM photos WHERE photo_id LIKE '$a%'";     
    $result_count = mysql_query($query_count, $connection);     
    $row_count = mysql_fetch_array($result_count, MYSQL_ASSOC);
    $totalrows = $row_count['rowcount'];

$limitvalue = $page * $limit - ($limit);  
    $query_thumbs  = "SELECT * FROM photos WHERE photo_id LIKE '$a%' ORDER BY photo_id LIMIT $limitvalue, $limit";         
    $result_thumbs = mysql_query($query_thumbs) or die("Error: " . mysql_error()); 


while ($row_thumbs = mysql_fetch_array($result_thumbs)) {
	extract($row_thumbs);	
	echo "<img id='$photo_id' src='$url' height='65px'> ";
}

    $numofpages = ceil($totalrows / $limit);  

    if($page > $numofpages){
    	$page = $numofpages;
    }

    if($page > 1){  
        $pageprev = $page - 1; 
         
        echo ("<a href=\"$PHP_SELF?go=photos&page=".$pageprev."\"><< PREV</a> - ");  
    }
     
    for($i = 1; $i <= $numofpages; $i++){ 
        if($i == $page){ 
            echo($i." "); 
        }else{ 
            echo("<a href=\"$PHP_SELF?go=photos&page=".$i."\">$i</a> "); 
        } 
    } 

    if($page < $numofpages){ 
        $pagenext = $page + 1; 
          
        echo(" - <a href=\"$PHP_SELF?go=photos&page=".$pagenext."\">NEXT >></a>");  
    }

?>
</td>

 

the layout is not great at the moment as im stillgetting it to function but the site addy is: http://travelling.dw20.co.uk/?go=photos

 

if anyone can see what is going wrong it would much help

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/124651-page-numbering/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.