Displaying a subset of records is limiting the information I can show
Hello All,
I'm developing my photo gallery's TOC page and when I began, I had lots of data I wanted to display and through the use of lookup tables and the proper logic in my SELECT query, I could show a vertical list of galleries that matched a specific category. With each was listed two sample thumbnails, title, description, model, photographer and make-up artist names. I even was able to set the page title and header to display the proper information.
An additoinal SELECT query counted the number of galleries in the main table that were relevant to the present query string value.
Another SELECT query counted the number of photos in each different gallery photoset and displayed that information in EACH gallery's title.
The description is in reverse to the flow of the code, keep in mind. Here is the code (the $spec variable is that of the query string.):
//get the total number of photos in a gallery photoset
$conn = dbConnect('query');
$getTotal = "SELECT COUNT(*)
FROM photos, galleries
WHERE galleries.g_spec = '$spec%'
AND galleries.g_id = photos.g_id ";
$total = $conn->query($getTotal);
$row = $total->fetch_row();
$totalPix = $row[0];
// get the number of galleries
$conn = dbConnect('query');
$getGtotal = "SELECT COUNT(*)
FROM galleries
WHERE galleries.g_spec = '$spec%' ";
$g_total = $conn->query($getGtotal);
$row = $g_total->fetch_row();
$galTotal = $row[0];
//get gallery thumbnails, name, description, subject, category, model, photographer, mua
$conn = dbConnect('query');
$sql = "SELECT g_thumb1, g_thumb2, g_name, g_desc, subject_id, category_id, model_name, photographer_name, mua_name
FROM galleries, gallery_spec, model_names, photographer_names, mua_names
WHERE galleries.g_spec = '$spec%'
AND gallery_spec.g_spec = galleries.g_spec
AND model_names.model_id = galleries.g_model
AND photographer_names.photographer_id = galleries.g_photographer
AND mua_names.mua_id = galleries.g_mua
ORDER BY g_id DESC ";
$result = $conn->query($sql) or die(mysqli_error());
$galSpec = $result->fetch_assoc();
*** end of code.
Anyhow, this worked wonderfully. However, as I add galleries, this list will get quite long. So, I wanted to add navigation which would break up the number of galleries into set quantities.
When I introduced parameters to LIMIT the number of queries displayed based on a variable called SHOWMAX, my displayed data got all botched. admittedly, I'm adapting code from David Powers' book PHP Solutions and am learning as I go. I gave up on displaying all of the data shown above and went the simple route, figuring I'd add more features as I learned. This necessitated restructuring my database a bit.
Here is the code I added that allows for navigation based on a limit of 3 entries per page:
// set maximum number of records per page
define('SHOWMAX', 3);
// get the number of galleries
$conn = dbConnect('query');
$getGtotal = "SELECT COUNT(*)
FROM galleries ";
$g_total = $conn->query($getGtotal);
$row = $g_total->fetch_row();
$galTotal = $row[0];
// set the current page
$curPage = isset($_GET['curPage']) ? $_GET['curPage'] : 0;
// retrieve subset of galleries
$conn = dbConnect('query');
// calculate the start row of the subset
$startRow = $curPage * SHOWMAX;
$sql = "SELECT *
FROM galleries
ORDER BY g_id DESC
LIMIT $startRow,".SHOWMAX;
$result = $conn->query($sql) or die(mysqli_error());
$galSpec = $result->fetch_assoc();
*** end of code.
Along with some navigation code in the body:
<div id="header4">
<p>Displaying <?php echo $startRow+1;
if ($startRow+1 < $galTotal) {
echo ' to ';
if ($startRow+SHOWMAX < $galTotal) {
echo $startRow+SHOWMAX;
}
else {
echo $galTotal;
}
}
echo " of $galTotal";
if ($curPage > 0) {
echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage-1).'"> Back </a>';
}
if ($startRow+SHOWMAX < $galTotal) {
echo '<a href="'.$_SERVER['PHP_SELF'].'?curPage='.($curPage+1).'"> Next </a>';
}
?>
I can now display my gallery information in groups of 3 per page.
THE PROBEM IS that when I add additional queries, say to get the subject and category information, model, photograpger and or make-up artist information, it doesn't always come up, sometimes it messes up the display, and in all cases, this additional information disappears when I navigate from subset to subset. This is why I have been asking about carrying values from one page to the next.
I am absolutely stonewalled and am going to have to put the galleries into service sans navigation until I can figure it out. I'm willing to even hire someone for advice. I just can not make this work. Yes, I realize it's complex for someone of my skill level, but I have no choice, I have to make this work.
Alternate forms of navigation/showing subsets of records would be greatly appreciated. ANY help, suggestions or guidance will be greatly appreciated.
Thank you for reading through all this.
Most sincerely,
wordman