PaRtiZzaN, this-> надо убрать
PaRtiZzaN, Мне кажется, много запросов ты нагородил
так проще (+/-)
$sth = $db->prepare("SELECT u.id, u.set_user, (
SELECT `text` FROM forum WHERE id = ?) as fname
FROM forum f
JOIN users u ON u.id = f.user_id
WHERE f.id = ?");
$sth->execute([$th, $id]);
$us = $sth->fetch();
$user_set = unserialize($us['set_user']) ?: $user_set = ['kmess' => 20];
$page1 = ceil($db->query("SELECT COUNT(*) FROM forum WHERE `type` = 'm' AND `refid` = '$th'")->fetchColumn() / ($user_set['kmess'] ?: 1));
$notifi = '<a href="/profile/?user=' . $systemUser->id . '">' . $systemUser->name . '</a> ' . (isset($_GET['cyt']) ? 'цитирует вас' : 'ответил вам') . ' в теме <a href="/forum/index.php?id=' . $th . '&page=' . $page1 . '">' . $us['fname'] . '</a>';
$db->prepare("INSERT INTO `cms_notification` (`user_id`, `text`, `date`) VALUES(?, ?, ?)")
->execute([$us['id'] , $notifi, time()]);