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
https://forums.phpfreaks.com/topic/210431-pagination-problem/
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.