pacchiee Posted August 13, 2007 Share Posted August 13, 2007 Hello Everybody, Here is a simple script which am using to fetch results from a database. It works fine but, I need to add paging to display only 10 results per page. Please help me out. //Start Script <?php $find = $_POST['find']; $find1 = mysql_query("SELECT * FROM tableaa WHERE aa_name LIKE '%$find%'"); $matches=mysql_num_rows($find1); if ($matches == 0 || $find == ""){ echo "No results were found"; }else{ while($result = mysql_fetch_array( $find1 )) { $aaId = $result['aa_id1'];$aaaId = $result['aa_id2']; $prod = getProductDetail($aaId, $aaaId); extract($prod); $result = mysql_query("SELECT * FROM table ab WHERE ab_id='$aaaId'"); $row = mysql_fetch_array( $result ); $pId = $row['p_id']; echo "<a href=index.php?cat=$pId&prod=$aaId>$aa_name</a>, $aa_price<br>$aa_description<br>"; } } ?> //End Script Thanks in Advance. Quote Link to comment https://forums.phpfreaks.com/topic/64669-solved-want-to-add-paging-in-search-result-page/ Share on other sites More sharing options...
ViN86 Posted August 13, 2007 Share Posted August 13, 2007 first, id return the number of entries via mysql_num_rows() once you get the number of rows, determine how many results per page you want. (ie, 55 results with 10 results per page would be 6 pages total. 5 with 10 and 1 with 5). create the links and have them point to the same page, then use the $_GET method to get the page number. based on the page number, modify the SELECT statement to retrieve only the number of results you want then use the while($var = mysql_fetch_array) statement to display all fields. the $_GET method would be done like... results.php?page=3 then $_GET['page'] would return the page number... 3 Quote Link to comment https://forums.phpfreaks.com/topic/64669-solved-want-to-add-paging-in-search-result-page/#findComment-322495 Share on other sites More sharing options...
reages Posted August 13, 2007 Share Posted August 13, 2007 change your mysql to include "LIMIT": $find1 = mysql_query("SELECT * FROM tableaa WHERE aa_name LIKE '%$find%' LIMIT $offset,$rows"); from mysql.com (http://dev.mysql.com/doc/refman/5.1/en/select.html) With two arguments, the first argument specifies the offset of the first row to return, and the second specifies the maximum number of rows to return. The offset of the initial row is 0 (not 1) so for the second page, with 10 pages per page, your variables should be: $offset=11 and $rows=10. regards. Quote Link to comment https://forums.phpfreaks.com/topic/64669-solved-want-to-add-paging-in-search-result-page/#findComment-322884 Share on other sites More sharing options...
pacchiee Posted August 14, 2007 Author Share Posted August 14, 2007 Thanks everybody, I was able to make it!! Quote Link to comment https://forums.phpfreaks.com/topic/64669-solved-want-to-add-paging-in-search-result-page/#findComment-323088 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.