almystersv Posted January 7, 2008 Share Posted January 7, 2008 Hi guys, Im having trouble getting my results to be displayed on a number of pages. i.e. results 1-10 on page 1, 11-20 on page 2 etc. I have got the results working on page 1 but then the same code but altered slightly does not work for page 2. Here is the code I have on page 1 that displays the results 1- 10. <?php $URN = 1; while($row = mysql_fetch_array($result)) if($URN <= 10) { ?> <tr> <td height="27"><div align="center"><?php echo $row['URN']?></div></td> <td><?php echo $row['productName']?></td> <td><?php echo $row['productType']?></td> <td><?php echo $row['description']?></td> <td>£<?php echo $row['price']?></td> <td width="34"><a href="addtobasketMain.php?URN=<?php echo $row['URN']?> &productName=<?php echo $row['productName']?> &description=<?php echo $row['description']?> &price=<?php echo $row['price']?>" > [+] </a></td> </tr> <?php $URN ++; } else { } ?> I need to modify this to show the results for 11-20 etc. Your help will be greatly appreciated. Cheers Link to comment https://forums.phpfreaks.com/topic/84859-solved-help-with-limiting-results/ Share on other sites More sharing options...
mike1313 Posted January 7, 2008 Share Posted January 7, 2008 Post more code like your selection query Link to comment https://forums.phpfreaks.com/topic/84859-solved-help-with-limiting-results/#findComment-432600 Share on other sites More sharing options...
adam291086 Posted January 7, 2008 Share Posted January 7, 2008 You need to look into pagination. There is a tutorial on this site. Link to comment https://forums.phpfreaks.com/topic/84859-solved-help-with-limiting-results/#findComment-432602 Share on other sites More sharing options...
almystersv Posted January 7, 2008 Author Share Posted January 7, 2008 Hi, My selection query is just SELECT * FROM PRODUCT ORDER BY URN; Link to comment https://forums.phpfreaks.com/topic/84859-solved-help-with-limiting-results/#findComment-432607 Share on other sites More sharing options...
Highlander Posted January 7, 2008 Share Posted January 7, 2008 <?php $query = " SELECT * FROM PRODUCT ORDER BY URN LIMIT 0, 10"; ?> Link to comment https://forums.phpfreaks.com/topic/84859-solved-help-with-limiting-results/#findComment-432608 Share on other sites More sharing options...
adam291086 Posted January 7, 2008 Share Posted January 7, 2008 like i said you need pagination. Here http://www.phpfreaks.com/tutorials/43/5.php Read this and learn. Link to comment https://forums.phpfreaks.com/topic/84859-solved-help-with-limiting-results/#findComment-432609 Share on other sites More sharing options...
Ken2k7 Posted January 7, 2008 Share Posted January 7, 2008 Maybe this will give you an idea on what you can do: <?php // database connection stuff // // this will get the page number from the URL // $page_number = $_GET['page']; // now you want to find out how many results you // want to display per page. // You may want to use mysql_num_rows and then // divide by $number_of_pages to get $results_per_page // if you're going to do that, take the ceil of $number_of_pages $number_of_pages = 20; $results_per_page = 10; // find the starting result of the page // if each page has $results_per_page results, it's easy to // find the starting point given $page_number $starting_point = ($page_number - 1) * $result_per_page + 1; // find ending result $ending_point = $page_number * $result_per_page // here is what your query should look like $query = "SELECT * FROM table_name LIMIT $starting_point, $ending_point"; // rest up to you, this is just to start you off in the right direction of thinking ?> Hope this helps Link to comment https://forums.phpfreaks.com/topic/84859-solved-help-with-limiting-results/#findComment-432610 Share on other sites More sharing options...
almystersv Posted January 7, 2008 Author Share Posted January 7, 2008 Thank you. Link to comment https://forums.phpfreaks.com/topic/84859-solved-help-with-limiting-results/#findComment-432752 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.