php - Counting all results of MySQL query for paging -
i building search page, each page featuring 10 results. purpose, display pages numbers @ bottom (like in google example) user can jump specific page result. in order need know overall count of query (e.g., if show 10 results per page , specific query returns 73 rows in table, need display links 8 pages).
the way can think of using following (obviously inefficient) query:
// query current page $res = mysql_query("select * table col='sample' limit $offset,10"); // geeting total count can build links other pages $res2 = mysql_query("select count(*) fromtable col='sample'");
is way it?
thanks,
danny
you can use
sql_calc_found_rows mysql> select sql_calc_found_rows * tbl_name -> id > 100 limit 10; mysql> select found_rows();
sql_calc_found_rows tells mysql calculate how many rows there in result set, disregarding limit clause. number of rows can retrieved select found_rows()
Comments
Post a Comment