Jump to content

[SOLVED] SQL Query Help


MrCreeky

Recommended Posts

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

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

?>

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

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.