Forum Moderators: coopster
// Count how many rows there are.
$query = "SELECT COUNT(keywords) FROM suppliers WHERE keywords LIKE '%$search_terms%'";
$result = @mysql_query($query);
if ($row = mysql_fetch_row($result)) $row_count = $row[0];
else $row_count = 0;// Make the query.
$query = "SELECT CONCAT(name_one, ' ', name_two) AS entries FROM suppliers WHERE keywords LIKE '%$search_terms%' OR name_one = '$search_terms' ORDER BY name_one ASC LIMIT $offset,$page_size";// Run the query.
$result = @mysql_query ($query);
I'm using the $row_count variable further down on the page, to make a set of links at the bottom, according to the number a pages I need - there are only ten search listing per page max. But I'm not getting this right. The first query seems to be counting the whole number of rows in the 'suppliers' table instead of the number of rows from the 'search' query.
Some assistance or pointers would be most appreciated.
MySQL 4.0 supports a fabulous new feature that allows you to get the number of rows that would have been returned if the query did not have a LIMIT clause. To use it, you need to add SQL_CALC_FOUND_ROWS to the query, e.g.$sql = "Select SQL_CALC_FOUND_ROWS * from table where state='CA' limit 50";
$result = mysql_query($sql);$sql = "Select FOUND_ROWS()";
$count_result = mysql_query($sql);You now have the total number of rows in table that match the criteria. This is great for knowing the total number of records when browsing through a list.