$qry = "SELECT COUNT(*) AS CountRows FROM messages WHERE id_msg=5";
$res = mysql_query($qry, $database);
$row = mysql_fetch_array($res);
$result = $row["CountRows"];
First Line: MySQL query
Second Line: Result of query ($database is the database connection variable)
Third Line: Row from result containing data, as an associative array
Fourth Line: Variable $result set to value
Hope this helps!