View Single Post
  #17 (permalink)  
Old 07-02-2008, 10:02 PM
gilgalbiblewhee gilgalbiblewhee is offline
Registered User
 
Join Date: Jul 2004
Posts: 249
Quote:
Originally Posted by curtiss View Post
The syntax of the COUNT() function can be found on the MySQL manual pages. Basically, all you do is add "COUNT(*)" in place of where you would normally use just "*". Using the COUNT query will simply return a single number telling you how many rows would be returned if you were to take out the COUNT() function from your query.

In other words, if you were to use a query like:
Code:
SELECT COUNT(*) FROM mytable
and there were 100 rows in "mytable", the result of that query would be 100.

Adding an alias for the COUNT function makes it easier to refer to the value that's returned by the query. So, in other words, you could use either of the following queries (they are both exactly the same, actually):
Code:
SELECT COUNT(*) totalrows FROM mytable
SELECT COUNT(*) AS totalrows FROM mytable
Then, you would simply refer to $rs['totalrows'] to get the number that is returned (assuming that $rs is the name of the array you are using to store your recordset).

Of course, if you place a limit on your results, and use the COUNT function with that limit, the COUNT function is only going to return whatever your limit is. So, if you use LIMIT 10 in your query, and there are at least ten rows that match the criteria in your query, the COUNT function is only going to return the number 10.

Therefore, when using the COUNT function, you want to take out the LIMIT phrase from your query. Other than that, you would just use the exact same query you are using to pull the information from your database in the first place.
Ok this is what the sql says:
Quote:
SELECT COUNT(*) AS totalrows FROM bible WHERE 1=1 AND CASE WHEN text_data LIKE '%offer%' THEN 1 ELSE 0 END + CASE WHEN text_data LIKE '%sacrifice%' THEN 1 ELSE 0 END + CASE WHEN text_data LIKE '%peace%' THEN 1 ELSE 0 END + CASE WHEN text_data LIKE '%offering%' THEN 1 ELSE 0 END + CASE WHEN text_data LIKE '%offering%' THEN 1 ELSE 0 END + CASE WHEN text_data LIKE '%covereth%' THEN 1 ELSE 0 END + CASE WHEN text_data LIKE '%inwards%' THEN 1 ELSE 0 END + CASE WHEN text_data LIKE '%inwards%' THEN 1 ELSE 0 END > 3 LIMIT 0, 10
When I use SELECT COUNT(*) AS totalrows it shows no results except 1:.
Reply With Quote