Jump to content

Pagination problem


bigheadedd

Recommended Posts

Hi guys,

 

I'm having a little problem with a pagination code i'm using.

Its for an image gallery, and I want to show the total amount of pictures in a set, and then the current picture displayed. I've got the total number, however its the current photo that i'm stuck on.

 

Its linked into a mysql database, with two tables, one for the categories and the other for the photos.

 

Category 1:

Image ID 1, 2, 3 etc

 

Category 2:

 

Image ID 4, 5, 6 etc

 

Now, my code works fine if they are all in order like this, but obviously images are deleted and replaced. so it could turn out like this:

 

Category 1:

Image ID 1, 2, 5, 8 etc

 

Here is the code:


$result = mysql_query("SELECT COUNT(photo_id) FROM gallery_photos WHERE photo_category='".addslashes($cid)."' GROUP BY photo_category ") or die(mysql_error());
list($num_rows)=mysql_fetch_array($result);
mysql_free_result( $result );

$counting = mysql_query("SELECT photo_id FROM gallery_photos WHERE photo_category='".addslashes($cid)."' ");



$counter="1";





			while($row = mysql_fetch_array($counting))
			{
				$id = $row['photo_id'];
				if($id == $pid)
				{
					if ($counter <= "9")
					{
						echo "0";
						echo $counter;
					} else 
					{
						echo $counter;
					} 
				} else {
				$counter++;
				}

			}		
			}				
			echo "/";
			if ($num_rows <= "9"){
				echo "0";
				echo $num_rows;
				} else {
				echo $num_rows;
				}
}

 

Any help would be hugely helpful as i'm really stuck on this!

 

Thanks

 

Edd

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.