MrCreeky Posted October 28, 2008 Share Posted October 28, 2008 I need a little help with how to achieve this result. I have a simple table and I need to show how many times a 20 record count could be returned. The end result is to show how many pages that show 20 results there are. i.e: Print page: 1 2 3 4 (each page showing 20 results) I have got the results pages working just fine but don't know how to COUNT all the records in that table and then divide them by 20 and print a result of 1 2 3 4. Here is the SQL I have so far: SELECT COUNT(rider) FROM tbec.rendlesham01 r Returns: 65 Could someone give me a point in the right direction? Link to comment https://forums.phpfreaks.com/topic/130419-solved-sql-query-help/ Share on other sites More sharing options...
rhodesa Posted October 28, 2008 Share Posted October 28, 2008 $rpp = 20; //records per page $count = 65; //this comes from your query $pages = ceil($count / $rpp); Link to comment https://forums.phpfreaks.com/topic/130419-solved-sql-query-help/#findComment-676515 Share on other sites More sharing options...
MrCreeky Posted October 28, 2008 Author Share Posted October 28, 2008 Thanks for getting back to me. I have tried using that but I get an odd result. I know there are 65 results in that table. 20 into 65 is 3.25 but the code returns a number 7? Also is there anyway to split the result into linkable numbers? <?php require_once('../../Connections/tbec.php'); mysql_select_db($database_tbec, $tbec); $query_Recordset1 = "SELECT rider FROM rendlesham01"; $Recordset1 = mysql_query($query_Recordset1, $tbec) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); $rpp = 20; //records per page $count = $row_Recordset1['rider']; //this comes from your query $pages = ceil($count / $rpp); print $pages ?> Link to comment https://forums.phpfreaks.com/topic/130419-solved-sql-query-help/#findComment-676554 Share on other sites More sharing options...
rhodesa Posted October 28, 2008 Share Posted October 28, 2008 no, like this: <?php require_once('../../Connections/tbec.php'); mysql_select_db($database_tbec, $tbec); $query_Recordset1 = "SELECT rider FROM rendlesham01"; $Recordset1 = mysql_query($query_Recordset1, $tbec) or die(mysql_error()); #$row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); $rpp = 20; //records per page $pages = ceil($totalRows_Recordset1 / $rpp); print $pages ?> Link to comment https://forums.phpfreaks.com/topic/130419-solved-sql-query-help/#findComment-676558 Share on other sites More sharing options...
rhodesa Posted October 28, 2008 Share Posted October 28, 2008 For more info on pagination, there is a THOROUGH tutorial here: http://www.phpfreaks.com/tutorial/basic-pagination Link to comment https://forums.phpfreaks.com/topic/130419-solved-sql-query-help/#findComment-676561 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.