Posts

Showing posts from November, 2008

[MySQL] Using SQL_CALC_FOUND_ROWS and FOUND_ROWS with MySQL

Hello, for this second blog article I've decided to explain this neat little feature of MySQL: SQL_CALC_FOUND_ROWS and FOUND_ROWS() . This article is about MySQL only, it is likely that these keywords/functions exist in other SQL-based languages but I've only ever used them with MySQL. What's the point, you ask? When working with (my)SQL databases, you often find yourself using the LIMIT keyword, in order for example to limit the results of a large search. Let's study a particular case. - You're working on the "employees" table, which contains, say 1000 data rows. - You wish to display the list of employees in a particular department, 10 by 10. - You wish to display the amount of employees in this department . What would you normally do? Here's a rough example: $result = mysql_query("SELECT * FROM employees WHERE department='sales' LIMIT 0,10 "); $total = mysql_num_rows($result); -> This is incorrect because $total will neve