The code below selects all of the coupons in my database and presents them on one page! How can I change it so that only 10 coupons show per page? <?php $con = mysql_connect("localhost","root"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ctyi", $con); $result = mysql_query("SELECT Coupon_Table.offer_anchor_text, Coupon_Table.offer_url, DATE_FORMAT(Coupon_Table.offer_expiration_date, '%d %M, %Y') AS formated_date, Coupon_Table.coupon_code, Advertiser_Table.advertiser_logo, Advertiser_Table.advertiser_name, Advertiser_Table.advertiser_url, Category_Table.category_name, Category_Table.category_url, Offer_Instructions_Table.block_anchor_text, Offer_Instructions_Table.offer_instructions FROM Coupon_Table, Advertiser_Table, Category_Table, Offer_Instructions_Table WHERE Coupon_Table.advertiser_id=Advertiser_Table.advertiser_id AND Coupon_Table.category_id=Category_Table.category_id AND Coupon_Table.offer_instructions_id=Offer_Instructions_Table.offer_instructions_id"); while($row = mysql_fetch_array($result)) { echo "<table border=\"0\">"; echo "<tr>"; echo "<td><img src=\"" . $row['advertiser_logo'] . "\" alt=\"\" /></td>"; echo "<td><a href=\"" . $row['offer_url'] . "\">" . $row['offer_anchor_text'] . "</a><br />"; echo (empty($row['coupon_code']) ? $row['offer_instructions'] : $row['coupon_code']); echo "<br /> Expires: " . $row['formated_date'] . "<br />"; echo "About <a href=\"" . $row['advertiser_url'] . "\">" . $row['advertiser_name'] . "</a><br />"; echo "Category: <a href=\"" . $row['category_url'] . "\">" . $row['category_name'] . "</a></td>"; echo "<td><a href=\"" . $row['offer_url'] . "\">" . $row['block_anchor_text'] . "</a></td>"; echo "</tr>"; echo "</table>"; } mysql_close($con); ?> PHP:
OK. But then it will just show 10 results on 1 page, right? I want pages 1, 2, 3, etc., to be generated and for 10 results to show per page. Do you know how I can do this?
You need to use Pagination. Which is not easy to setup. If your using a framework, it may already have a pagination class.
Yes, doing pagination is bit tricky, but not tough Here is an article which works perfect, i tested it .. just go ahead with that and customize according to your requirements . ITTreats.com- Pagination in PHP
Thanks for the help, guys! I repped those of you who mentioned pagination. Just in case someone else is interested, I found this excellent, simplified tutorial on pagination: http://www.phpfreaks.com/tutorial/basic-pagination Check it out.