public function message_count($id_user = null)
{
try {
// Если id_user не указан, берем его по текущей сессии.
if ($id_user == null)
$id_user = $this->GetUid();
// А теперь просто возвращаем пользователя по id_user.
$dbh = new PDO("mysql::host=$this->hostname;dbname=$this->dbName", $this->username, $this->password, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''));
//$sql = "SELECT users.login, sessions.id_user FROM users, sessions WHERE users.id_user = sessions.id_user GROUP BY users.login HAVING sessions.id_user > '0'";
$sql = "SELECT DISTINCT COUNT(id_user_take) AS count FROM messages, users WHERE id_user_take = '$id_user' AND id_user = '$id_user'";
return $dbh->query($sql);
$dbh = NULL; // Закрываем соединение
}
catch (PDOException $e)
{
return $e->getMessage();
}
}