View Single Post
  #15 (permalink)  
Old 06-27-2008, 09:11 PM
curtiss's Avatar
curtiss curtiss is offline
Moderator
 
Join Date: May 2003
Posts: 1,438
First of all, yes, I am saying that it appears to be the $searchthese that's causing the problem.

The rest of your SQL query does not get built if $searchTheseArr is empty, and that appears to be what's happening.

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.
__________________
I hate Internet Explorer! Anyone with me?
Reply With Quote