Jump to content

selecting certain records


c_pattle

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

Archived

This topic is now archived and is closed to further replies.

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