35 lines
965 B
PHP
35 lines
965 B
PHP
<?php
|
|
$root = realpath($_SERVER["DOCUMENT_ROOT"]);
|
|
require "$root/database/credentials.php";
|
|
// Connect the database
|
|
try {
|
|
$db = new PDO("mysql:host=$host;dbname=$database;charset=utf8",
|
|
$user,
|
|
$password,
|
|
array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
|
|
));
|
|
} catch (Exception $e) {
|
|
die("Error : ".$e->getMessage());
|
|
}
|
|
|
|
if (isset($_SESSION['username'])) {
|
|
$req = $db->prepare('SELECT id FROM `authors` WHERE username=:username');
|
|
$req->execute(array(
|
|
"username"=>$_SESSION['username']
|
|
));
|
|
$data = $req->fetch();
|
|
$user_id = $data['id'];
|
|
$req = $db->prepare('SELECT COUNT(*) AS counter FROM `messages` WHERE message_to=:user_id AND message_read=0');
|
|
$req->execute(array(
|
|
"user_id"=>$user_id
|
|
));
|
|
$data = $req->fetch();
|
|
$new_msg_number = $data['counter'];
|
|
if ($new_msg_number != 0) {
|
|
?>
|
|
<span class="badge"><?=$new_msg_number?></span>
|
|
<?php
|
|
}
|
|
} else {
|
|
echo "";
|
|
}
|