Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/200558-help-product-gallery-mysql/
Share on other sites

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 ;)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.