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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.