CBStrauss Posted November 9, 2009 Share Posted November 9, 2009 I posted a subject last week and got the help on figuring out how to make next and previous button for an image gallery. Here is the link to that topic. http://www.phpfreaks.com/forums/index.php/topic,275729.msg1304633.html#msg1304633 Now on to my current problem I'm trying to add that logic to my current gallery script, but I'm obviously not understanding something. Obviously the next and previous buttons are working as well as they can, except they are displaying the right images, When I hit the next button or previous button it just loads the current image again then will cycle through the others but at times skips images are displays them out of order. Here is my code Im working with I will try to break it up and comment where need be. This is basically the main page that shows the thumbnails, you click on thumb and takes you to the full size image this works fine. Showing in case there is something I'm missing to make the second part work. include $_SERVER['DOCUMENT_ROOT'].'/classes/clsPaging.php'; // Connect To DB // Get the current index from of the URL. //Set Page Links if(!isset($_GET['page'])){ $_GET['page'] = 1; } $page=$_GET['page']; $limit = 2; $num_records = @mysql_query("SELECT COUNT(*) FROM gallery") or die (mysql_error()); $total = mysql_result($num_records,0,0); $link = 'gallery.php?page='.$_GET['page']; // Work out the pager values $pager = Pager::getPagerData($total,$limit,$page); $offset = $pager->offset; $limit = $pager->limit; $page = $pager->page; // Query Database To Get Screen Shots $sql = @mysql_query("SELECT * FROM gallery ORDER BY img_id DESC LIMIT $offset,$limit"); if(!$sql){ echo "Error With MySQL Query: ".mysql_error(); } ?> <td class="contentStatic" valign="top"> <div id="gallery"> <div class="deftxt" style="padding-bottom:10px;" align="center"> <? include $_SERVER['DOCUMENT_ROOT'].'/inc/paging_system.php'; ?> </div> <!-- Thumbs Section --> <table width="100%" border="1" bordercolor="#000"> <tr> <? $loopvar = 0; while($row = mysql_fetch_assoc($sql)){ stripslashes(extract($row)); if($loopvar % 2 == 0){ ?> </tr><tr align="center"><td class="galleryItem"><a href="/imageview.php?img_id=<?=$img_id;?>&page=<?=$page;?>"><img src="/gallery/art_tn/<?=$img_tnName;?>" class="imgLink" /></a> <br /> <?=$img_title;?></td> <? }else{ ?> <td class="galleryItem"><a href="/imageview.php?img_id=<?=$img_id;?>&page=<?=$page;?>"><img src="/gallery/art_tn/<?=$img_tnName;?>" class="imgLink" /></a><br /> <?=$img_title;?></td> <? } $loopvar++; } ?> </tr> </table> <!-- End Thumbs Section --> </div> </td> This is the code that displays after click the thumb to show the fullsize image <? //Database Connetion Here. $img_id = $_GET['img_id']; $page = $_GET['page']; // Get Image From Databasee $sql = mysql_query("SELECT * ,date_format(img_date,'%M %D, %Y') as img_date FROM gallery WHERE img_id='{$_GET['img_id']}' LIMIT 1"); if(!$sql){ echo "Error performing query: ".mysql_error(); } $row = mysql_fetch_assoc($sql); stripslashes(extract($row)) ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Artwork Of Chris Strauss - <?php echo $img_title;?></title> <link rel="stylesheet" href="styles.css" type="text/css" media="all" /> </head> <body class="siteBg"> <div id="page" class="page"> <table width="1000" cellpadding="0" cellspacing="0" border="0" bordercolor="#FFFF00"> <tr> <td class="galleryHeader"> </td> </tr> <tr> <td><table border="0" cellpadding="0" cellspacing="0"> <tr> <td class="contentBg2"> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td align="center" > <img class="imageItem" src="/gallery/art_large/<?=$img_filename;?>" alt="<?=$img_title;?>" title=""> </td> </tr> <tr> <td align="center" class="title"><?=$img_title;?></td> </tr> <tr> <td> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <?php // Get the current index from of the URL. $curIndex = isset($_GET['index']) ? (int) $_GET['index'] : 0; // Get the total number of rows in the table. // We will use this information to determine the $nextIndex. $result = mysql_query(" SELECT COUNT(img_id) AS numRows FROM gallery ") or die(mysql_error()); $numRowsTotal = mysql_result($result, 0, 'numRows'); if ($curIndex + 1 >= $numRowsTotal) { $nextIndex = 0; } else { $nextIndex = $curIndex + 1; } if($curIndex == 0){ $prevIndex = $numRowsTotal - 1; }else{ $prevIndex = $curIndex - 1; } // Get a single record out of the table from the $curIndex position. $result = mysql_query(" SELECT * FROM gallery ORDER BY img_id DESC LIMIT $curIndex, 1 ") or die(mysql_error()); if (mysql_num_rows($result) > 0) { $row = mysql_fetch_assoc($result); // Display its information for testing purposes. echo "<pre>"; print_r($row); echo "</pre>"; echo $nextIndex; } ?> <td align="center" class="linkClass1" width="33%"><a href="?index=<?= $prevIndex;?>&img_id=<?=$img_id;?>&page=<?=$page;?>">Back</a></td> <td align="center" class="linkClass1" width="33%"><a href="/gallery.php?page=<?=$page;?>">go back</a></td> <td align="center" class="linkClass1" width="33%"><a href="?index=<?= $nextIndex;?>&img_id=<?=$img_id;?>&page=<?=$page;?>">Next</a></td> </tr> </table> </td> </tr> </table> </td> </tr> </table> <tr> <td><img src="images/footer_19.jpg" alt="" title="" /></td> </tr> </table> </div><!-- End Page Div --> </body> </html> Now the first set of php code at the top obviously taking the img_id so it knows what image to get out of the database and the page variable just to keep track of the last page you where on for the go back button. Now Here is where my problem comes in at the bottom (the last set of PHP code) is the code Im trying to implement into from my last topic to give the ability to just start going through the large view images if the user wishes rather then go back to thumbnail page. now it seems my problem is my img_id and nextIndex/curIndex/prevIndex variables are not matching up. and I'm trying to figure out away to get the img_id value to match the nextIndex and prevIndex value so when you click those links they will go to the right image. I realize the reason it goes to the same image the first time you click is cause the value being passed is actually the current img_id. Anyone have an Idea of what I need to do to get my code working or do I have a problem that is just impossible to do? Thanks in advance for any ideas you might have. Link to comment https://forums.phpfreaks.com/topic/180883-having-a-problem-passing-a-value-through-a-link/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.