c_pattle Posted June 1, 2010 Share Posted June 1, 2010 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 ++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/203533-selecting-certain-records/ Share on other sites More sharing options...
premiso Posted June 1, 2010 Share Posted June 1, 2010 Take a look at this tutorial: http://www.phpfreaks.com/tutorial/basic-pagination It goes over the basics of pagination, which is what you are trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/203533-selecting-certain-records/#findComment-1066204 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.