Reputation: 187
I'm making a search application, and I want to figure out how many results a certain query fetches in order to calculate how many pages of results there are. I basically have:
mysql_query("SELECT * FROM table WHERE conditions LIMIT $page*$items, $items");
Do I have to do a query w/o the limit clause to get the total number, or is there a better way? Thanks!
Upvotes: 0
Views: 674
Reputation: 4601
$page_count=10 // no of rows per page
$record=mysql_query("select count(*) from table where conditions");
$row=mysql_fetch_row[0];
$no_of_pages = ceil($row/$page_count);
Upvotes: 0
Reputation: 43434
I see you're using PHP. Once you've run the query, why don't you mysql_num_rows
in PHP? That way you won't need to run two queries.
Upvotes: 2