I have an image gallery split down into 3 categories and in my database I have fields for id, image, thumbnail and category.
What I am trying to do is display only the images that belong to that category but what I am having trouble with is counting the images.
I would like to count all the images belonging to a category and display something like
Showing image 1 of 10 where 10 is the maximum number of images belonging to that category.
I have tried this but it is using the id number so it displays something like Showing image 25 of 23 . I have mananged to count the max number but how do I start the numbering from 1 so the image number would be starting from 1 - 23?
I want to count the number of images in the category, and say there are 15 images, I want to start the counting from 1 to 15, not by the ID number which it is currently started by.
Here is my code:
<?
echo "<h2>Image Gallery - ".$cat."</h2>";
echo "<div style='text-align:center'>";
//REMEMBER TO CONNECT TO DATABASE!
include_once("includes/connection.php");
//**EDIT TO YOUR TABLE NAME, ECT.
$t = mysql_query("SELECT * FROM images");
if(!$t) die(mysql_error());
$a = mysql_fetch_object($t);
$total_items = mysql_num_rows($t);
$limit = $_GET['limit'];
$type = $_GET['type'];
$page = $_GET['id'];
$cat = $_GET['cat'];
//set default if: $limit is empty, non numerical, less than 1, greater than 50
if((!$limit) || (is_numeric($limit) == false) || ($limit < 2) || ($limit > 50)) {
$limit = 1; //default
}
//set default if: $page is empty, non numerical, less than zero, greater than total available
if((!$page) || (is_numeric($page) == false) || ($page < 0) || ($page > $total_items)) {
$page = 1; //default
}
//calcuate total pages
$total_pages = ceil($total_items / $limit);
$set_limit = $page * $limit - ($limit);
$count = mysql_query("SELECT COUNT(*) FROM images");
//query: **EDIT TO YOUR TABLE NAME, ECT.
$q = mysql_query("SELECT * FROM images WHERE id = '$page'");
if(!$q) die(mysql_error());
$err = mysql_num_rows($q);
if($err == 0) die("No matches met your criteria.");
$numofrows = mysql_num_rows($q);
//show data matching query:
while($code = mysql_fetch_array($q)) {
echo "<p><b>".$page."</b> of <b>".$count1 = mysql_result($count,0,0)."</b></p>";
echo "<img src='/images/gallery/large/".$code['image']."'><br/><br/>";
}
//prev. page: **EDIT LINK PATH**
$prev_page = $page - 1;
if($prev_page >= 1) {
echo("<<<a href=/gallery/$cat/image/$prev_page>Prev. </a>");
}
//Display middle pages: **EDIT LINK PATH**
echo "<b>".$page."</b>";
//next page: **EDIT THIS LINK PATH**
$next_page = $page + 1;
if($next_page <= $total_pages) {
echo("<a href=/gallery/$cat/image/$next_page> Next</a> >>");
}
//all done
?></div>