I have a database and I have 3 different values that I want to count, to say that You have x amount of tickets open. I am created an array

$array = array(
    'Pending', 'Waiting on parts', 'Waiting for customer response'

and a query string

$result = mysql_query("SELECT COUNT(*) FROM computerdb WHERE email = '$id' AND FIND_IN_SET($array,'status' );"); list ( $count ) = mysql_fetch_row ( $result ); echo $count

for some reason it will not count it just errors out...

Error 1:
Warning: in_array() [function.in-array]: Wrong datatype for second argument in
Error 2:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource

Any ideas?

Member Avatar
SELECT field1, COUNT(field1) FROM table WHERE field2 = somevalue GROUP BY(field1)

will give you UP TO 3 records in your example

all it is doing is saying: 'You have Completed tickets open.', I dont want it to say completed, it needs to day you have x (x = 1 - infinity) tickets open and only for their id excluding completed...

Member Avatar

Your status field should be numerical not textual, i.e. a foreign key from a 'status' table , e.g.

1 = Pending
2 = Waiting on parts


text searches are not only slow but they are prone to errors.
If your status categories will never be more than 32 in number, you could use bitwise operators for searches, such as...

Pending: 1
Waiting on parts: 2
Waiting for customer response: 4
Something else: 8
Something else again: 16

So your custom search if you wanted Pending, Waiting on parts or Waiting for customer response would be...

$filter = 8;
$query = "SELECT... WHERE $filter & status > 0"; 

But that's something else