Andy11548 Posted July 9, 2011 Share Posted July 9, 2011 Hey, I'm making a forums and wondering how to make it so after like 15 topics are posted, it creates a new page so that it would be like Pages: 1 2 3 4 5 etc. Thanks, Andy. Quote Link to comment https://forums.phpfreaks.com/topic/241497-new-pages/ Share on other sites More sharing options...
wildteen88 Posted July 9, 2011 Share Posted July 9, 2011 To create pages from results of your queries you need to use pagination Quote Link to comment https://forums.phpfreaks.com/topic/241497-new-pages/#findComment-1240503 Share on other sites More sharing options...
Andy11548 Posted July 9, 2011 Author Share Posted July 9, 2011 Thanks, this looks really confusing, so I guess I best spend some time reading into this and working it out. Is it as hard as it looks? Quote Link to comment https://forums.phpfreaks.com/topic/241497-new-pages/#findComment-1240508 Share on other sites More sharing options...
wildteen88 Posted July 9, 2011 Share Posted July 9, 2011 The code in that tutorial is what you'll need to use in order to make page links. There is no built-in function that will do this for you. The code is actually very simple. You will only need to modify a cople of lines of code to make it work with your code. The first bit of code you need to modify is this part // find out how many rows are in the table $sql = "SELECT COUNT(*) FROM numbers"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; You will only need to edit the sql query ($sql = "SELECT COUNT(*) FROM numbers";) so it returns the number of threads in the current forum. The next bit you edit // get the info from the db $sql = "SELECT id, number FROM numbers LIMIT $offset, $rowsperpage"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { // echo data echo $list['id'] . " : " . $list['number'] . "<br />"; } // end while In the above block you can just replace the query ($sql) which your current query for getting the threads. Just add LIMIT $offset, $rowsperpage to the end of your query And finally replace the while loop which your loop for displaying the threads. Quote Link to comment https://forums.phpfreaks.com/topic/241497-new-pages/#findComment-1240521 Share on other sites More sharing options...
Andy11548 Posted July 9, 2011 Author Share Posted July 9, 2011 I was about to ask the dumbest question ever. "What is the 'numbers' part all about in the SQL?" it confused me for about 10 minuets then it struck me and I started laughing at my stupidity lmao. I will crack on and see how it goes. Thanks for your help, I really appriciate it. Thanks again, Andy. Quote Link to comment https://forums.phpfreaks.com/topic/241497-new-pages/#findComment-1240527 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.