Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting Count of all rows when using LIMIT

Status
Not open for further replies.

philclare

Programmer
Jul 31, 2003
34
GB
Is there anyway that I can get the number of rows that a query would have returned if I hadn't used the LIMIT clause?

I have a database with 6000 records and when I execute a query I want to page the results, but also need to know how many results there are altogether so that I can work out how many pages to offer etc...

For an example have a look at PHPMyAdmin, execute a quey on the database and at the top it will say "Showing rows 0 - 29 (62 total)".

How do I do this without executing the query twice (once with and once without the LIMIT clause)

Thanks

Hope this helps,

Phil Clare
 
make it two queries
$start=0;
$offset=30;

Code:
$query="select count(rowid)as totaal from table";
$rs1=mysql_query($query,$conn);
$row = mysql_fetch_array($rs1); 
$totaal=$row["totaal"];

$query="select * from table limit " .$start.",".$offset;
$rs2=mysql_query($query,$conn);
$row = mysql_fetch_array($rs2); 
$field1=$row["field1"];

echo "show rows". $start "-" . $start+$offset ."(".$totaal.")";

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top