计算MySQL中的特定行

If I want to count one specific row (unread) in my database, how should i proceed with this MySQL query? As of now it counts the whole table.

$result_notifications = mysql_query("select count(1) FROM bhost_notifications where taker_id='$user_info[u_id]'");
$row_notifications = mysql_fetch_array($result_notifications);
$total_notifications = $row_notifications[0];

You need to alias the column.

SELECT COUNT(1) AS count ...

Then you would call $row_followers[count]. Be aware that mysql_ functions are deprecated. Learn about prepared statements when passing variables, and use PDO or MySQLi - this article will help you decide which.

I suspect you have an un-normalized database. While that is preferable in some situations, I doubt that they are in yours. As written you cannot be sure that the query will return the row you desire. SQL does not guarantee the order of rows, unless you use an order by clause.

It seems like this question indicates more problems the some syntax issues.

Over time I have written a nice function in PHP that allows me to easily look up records but still be dynamic enough to be useful in every type of query that I perform.

Usage:

if (get("select * from table", $query_array) > 0)
{
 // There is at least one row returned
 $result_array = mysql_fetch_array($query_array);
 .
 .
 .
} else {
 // No rows in the set
}

Function:

function get($sql, &$array)
{
 $array = "";
 $q = mysql_query($sql);
 if (mysql_error())
 {
  $ret = -1;
  print "<div><font style='font-family: arial; font-size: 12px;'><font style='color: red;'>Error:</font> " . mysql_error() . "<br>SQL: #sql</font></div>";
  exit(1);
 } else {
  $ret = mysql_num_rows($q);
  if ($ret > 0)
  {
   $array = $q;
  }
 }
 return $ret;
}

This also gives a formatted error message in the case that there is something wron with the query. I use this all the time because it compresses the mysql_query and mysql_num_rows together into a single command.