squiblo Posted July 30, 2009 Share Posted July 30, 2009 I would like to just show 10 results per page but how do I do this, and how do I create the pages? <font face="arial"> <?php //get data $button = $_GET['submit']; $search = $_GET['search']; if (!$button) header("location:unititled.php"); else { if (strlen($search)<3) header("location:unititled.php"); else { echo ""; //connect to our database mysql_connect("localhost","",""); mysql_select_db(""); //explode our search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { //construct query $x++; if ($x==1) $construct .= "username LIKE '%$search_each%'"; else $construct .= " OR username LIKE '%$search_each%'"; } //echo out construct $construct = "SELECT * FROM members WHERE $construct"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "No results found."; else { echo "You searched for <b>$search</b><br>$foundnum result(s) found!<p><hr size='1' width='300'color='#E6E6E6'>"; while ($runrows = mysql_fetch_assoc($run)) { //get data $state = ucwords($runrows['state']); $url = $runrows['url']; $username = ucwords($runrows['username']); $imagelocation = $runrows['imagelocation']; if ($imagelocation == "") { $imagelocation = "./profileimages/box.png"; } echo " <img src ='$imagelocation' width='100' height='105' border='0' align='left' style='padding-right:10px'><br> <b>$username</b><br> $state<br> <a href='$url'>View Profile</a><br><br><br> <hr size='1' width='300' align='left' color='#E6E6E6'> "; } } } } ?> </font> Quote Link to comment https://forums.phpfreaks.com/topic/168174-pages-and-results-per-page/ Share on other sites More sharing options...
squiblo Posted July 30, 2009 Author Share Posted July 30, 2009 firstly, how can I set 10 results per page? Quote Link to comment https://forums.phpfreaks.com/topic/168174-pages-and-results-per-page/#findComment-886999 Share on other sites More sharing options...
squiblo Posted July 30, 2009 Author Share Posted July 30, 2009 ive tried everything anyone? Quote Link to comment https://forums.phpfreaks.com/topic/168174-pages-and-results-per-page/#findComment-887032 Share on other sites More sharing options...
TeNDoLLA Posted July 30, 2009 Share Posted July 30, 2009 Theres nothing in your code that would deal with the paging ? The basics of creating paging would go about follorwing way... 1. You get result amount and calculate max pages. 2. Based on max pages you create links for the paging. 3. When link is clicked you calculate the offset and limit values for SQL query based on the page. 4. Run a query eg. "SELECT somevalues FROM sometable WHERE here_year_search_conditions LIMIT $offset, $rowsPerPage" (and of course between this process you have to store soemwhere your search results so they won't disappear during page change. eg. in session variables) Also there is a lot of tutorials if you search eg. with words "paging php" or "php paging tutorial", also there is available ready codes for that. Quote Link to comment https://forums.phpfreaks.com/topic/168174-pages-and-results-per-page/#findComment-887034 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.