Whats wrong with this?

$unread = mysql_query(“SELECT * FROM tickets WHERE status=‘Open’”);
$unread_tick = mysql_num_rows($unread);

echo “<br /><p><center>$unread_tick ticket is awaiting a response!</center></p>”;

There is a row in the tickets table, with status = Open.

It will just display 0 tickets, but if I just use “SELECT * FROM tickets” it will display the number perfect. But the above query will work perfectly in phpmyadmin.

It would be better to count the number of records in the query itself, instead of returning the entire rowset.
E.g.:


$unreadRecord = mysql_query("SELECT COUNT(id) AS unread FROM tickets WHERE status='Open'");
$unreadRecord = mysql_fetch_assoc($unreadRecord);
$unreadTickets = $unreadRecord['unread'];

echo '<br/><p class="text-align-center">', $unreadTickets, ($unreadTickets==1 ? ' ticket is' : ' tickets are'), ' awaiting response!</p>';

Edit: cranial-bore, I couldn’t have said it better :o)

What if you put backticks around status?

SELECT * FROM tickets WHERE `status`='Open'

And this is a bit of a side issue, but there is no reason to select every column of all the Open rows, just to find out how many rows there are.
Do something like this instead:


if(!$unread = mysql_query("SELECT count(*) AS open_tickets FROM tickets WHERE status='Open'")) {
  echo "MySQL Error: " . mysql_error();
  exit;
}
$r = mysql_fetch_assoc($unread);

echo "&lt;p style='text-align: center;'&gt;$r[open_tickets] tickets awaiting a response!&lt;/p&gt;";

You should never use SELECT *, and should use a COUNT when that is what you need.