PC Nerd Posted July 16, 2006 Share Posted July 16, 2006 i want to create a page, which loops on itself, eg page.phpthe page sources from a very large database, so i want to display 20 entrys per page, and display them in order of points, then alphabetically. i dont want to display enrtys multiple time.i havent written any PHP, but im thinking of how to approach this problem.All help is much appreciated,Pc Nerd Quote Link to comment https://forums.phpfreaks.com/topic/14765-keeping-note-of-where-you-are/ Share on other sites More sharing options...
tomfmason Posted July 16, 2006 Share Posted July 16, 2006 Now I think that most of this can be solved with your approach towards searching the data base. To display results by a specific order you can use something like this:[code=php:0]$query = "SELECT search1, search2 FROM your_table ORDER BY your_order limit 0, 20";[/code]I wrote this quickly so you might want to search the manual for the proper syntax. Hopefully this will help alittle. Quote Link to comment https://forums.phpfreaks.com/topic/14765-keeping-note-of-where-you-are/#findComment-58942 Share on other sites More sharing options...
PC Nerd Posted July 16, 2006 Author Share Posted July 16, 2006 ok. then how would i display enrties 20 - 40and there fore would i have to create a script that would re-rank the entrys. (im writing a game, so the database is continually minipulated)if so, how would i write it so that it runns every, 20 minute (or like), without me having to continually manually run the script. i want the site to be as sent maintaing as possiblethanks for your help with that query,PC Nerd Quote Link to comment https://forums.phpfreaks.com/topic/14765-keeping-note-of-where-you-are/#findComment-58943 Share on other sites More sharing options...
tomfmason Posted July 16, 2006 Share Posted July 16, 2006 this tutorial should help you with what you are wanting [url=http://www.phpfreaks.com/tutorials/43/1.php]http://www.phpfreaks.com/tutorials/43/1.php[/url] at least as far as the pagination end. Quote Link to comment https://forums.phpfreaks.com/topic/14765-keeping-note-of-where-you-are/#findComment-58947 Share on other sites More sharing options...
redarrow Posted July 16, 2006 Share Posted July 16, 2006 <?php @mysql_connect($localhost, $user, $password) or die("ERROR--CAN'T CONNECT TO SERVER"); @mysql_select_db($database) or die("ERROR--CAN'T CONNECT TO DB"); $limit = 20; $query_count = "SELECT count(*) FROM table"; $result_count = mysql_query($query_count); $totalrows = mysql_num_rows($result_count); if(empty($page)){ $page = 1; } $limitvalue = $page * $limit - ($limit); $query = "SELECT search1,search2 FROM table_name LIMIT $limitvalue, $limit"; $result = mysql_query($query) or die("Error: " . mysql_error()); if(mysql_num_rows($result) == 0){ echo("Nothing to Display!"); } echo("<table>"); while($row = mysql_fetch_array($result)){ echo $row['what_ever']; } echo("</table>"); if($page != 1){ $pageprev = $page--; echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> "); }else{ echo("PREV".$limit." "); } $numofpages = $totalrows / $limit; for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"$PHP_SELF?page=$i\">$i</a> "); } } if(($totalrows % $limit) != 0){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"$PHP_SELF?page=$i\">$i</a> "); } } if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page++; echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>"); }else{ echo("NEXT".$limit); } mysql_free_result($result); ?> There you go good luck. Quote Link to comment https://forums.phpfreaks.com/topic/14765-keeping-note-of-where-you-are/#findComment-58950 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.