Jump to content

Recommended Posts

I have a page that select all the products from a mysql table and then prints them out to the screen.  However there are over 100 products so I want to be able to make it so it prints out 0-30, then when the user clicks next it displays 30-60 etc. 

 

What I've done so far is if you click next or previous it adds and takes away 30.  So if you click next it display 0-60 and if you click previous it display 0-30.  However how can I make it so that it doesn't always start at 0.  Hope this makes sense.  I've copied my code below. 

 

<a href="add_records.php?key19=30">previous</a>
<a href="add_records.php?key20=30">next</a>

<?php

//Fetching data from database and printing it out
$row_count = 1;
$row_max = 31;
if (isset($_GET['key20'])) {

$row_max +=30;
}

if (isset($_GET['key19'])) {
$_row_max -= 30;
}

while (( $row = mysql_fetch_array ( $rs ) ) and ($row_count < $row_max)) {
$table_row = "<tr><td>" . $row["id"] . "</td><td>" . $row["product_name"] . "</td><td>" . $row["price"] . "</td><td>" . $row["product_description"] . "</td><td>" . $row["department"] . "</td><td>" . $row["category"] . "</td><td>" . $row["size"] . "</td></tr>";
echo ($table_row);
$row_count ++;
}

?>

Link to comment
https://forums.phpfreaks.com/topic/203533-selecting-certain-records/
Share on other sites

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.