Using 'mysql_num_rows(mysql_query('...'))' is a VERY bad idea. This causes too much overhead on MySQL and will create slow page loads when the number of pages becomes too great.
Instead, use this little nifty trick to get the total number of rows, regardless of what you set for a LIMIT in the query, ex.:
SELECT SQL_CALC_FOUND_ROWS * FROM tblData LIMIT 0, 30;
and then do:
SELECT FOUND_ROWS();
The first query will return your first 30 records, while the second query will return how many rows would have been returned without the use of LIMIT.
This is much better suited for these types of scenarios, since you won't have to actually pull every single record or use any expensive aggregate functions to find out something this simple.
You should not use ternary operators. They simply obfuscate the code for beginning programmers and those unfamiliar with language. As a site targeted at providing examples, the code should be more well documented.
Instead, use this little nifty trick to get the total number of rows, regardless of what you set for a LIMIT in the query, ex.:
SELECT SQL_CALC_FOUND_ROWS * FROM tblData LIMIT 0, 30;
and then do:
SELECT FOUND_ROWS();
The first query will return your first 30 records, while the second query will return how many rows would have been returned without the use of LIMIT.
This is much better suited for these types of scenarios, since you won't have to actually pull every single record or use any expensive aggregate functions to find out something this simple.