GPL Posted May 3, 2010 Share Posted May 3, 2010 Hello, I am trying to make a page that connects to a DB that has a field with an image directory and its price, and i need to make pagination to show all products in that table but one at each time. How can i make a previous and next button to go trough the DB table and display all content, showing one product each time and having a previous and next button? thank you Quote Link to comment https://forums.phpfreaks.com/topic/200558-help-product-gallery-mysql/ Share on other sites More sharing options...
Muddy_Funster Posted May 3, 2010 Share Posted May 3, 2010 Assuming that your table has a numerical index key then you can use SELECT COUNT(id) FROM tableName assigne that to a variable and have a $counter on the page that cross refferences a SELECT image, price FROM tableName where id = $counter . This is not tested and is very messy as I just knocked it up quick, but I would suggest something a little like: <?php $qry = "SELECT COUNT(id) FROM tableName"; $count = mysql_fetch_array(mysql_query($qry)); $db_count = $count['0']; $_SESSION['max_count'] = $db_count; $_SESSION['min_count'] = $db_count - $db_count; if ($_SESSION['browsing'] != "Yes"){ $counter = $min_count; $_SESSION['browsing'] = "Yes"; } else{ $counter = $_POST['new_counter'] } if ($counter => $_SESSION['min_count'] && $counter =< $_SESSION['max_count']){ echo 'Image No. '.$counter.' of '.$_SESSION['max_count']; $get_image = "SELECT image, price FROM tableName WHERE id = ".$counter; $got_image = mysql_query($get_image); $image_info = mysql_fetch_assoc($got_image); printf $image_info['image']; echo "<br> Priced at &dolar;".$image_info['price']; if ($counter > $_SESSION['min_count']){ echo '<form action ="PHP_SELF" method="post" type="submit"><input type="hidden" value="'.($counter - 1).'" name="new_counter" /></form>'; } elseif ($counter < $_SESSION['max_count']){ echo '<form action ="PHP_SELF" method="post" type="submit"><input type="hidden" value="'.($counter + 1).'" name="new_counter" /></form>'; } } else {echo 'Value out of range, an error has occured';} ?> **I STRESS this is just to give you the idea of what I am talking about - this has not been error checked at all!!** Hope it helps though Quote Link to comment https://forums.phpfreaks.com/topic/200558-help-product-gallery-mysql/#findComment-1052426 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.