I have a function that accesses the database to get a message based on the recipients UserID.
function GetUnreadMessages($recipientID, $db) {
$sql = 'SELECT
senderID AND headline AND message
FROM
Message
WHERE
recipientID = ? AND unread = 1
LIMIT 100';
$stmt = $db->prepare($sql);
if ($stmt) {
$stmt->bind_param('i', $recipientID);
$stmt->execute();
return $stmt->get_result();
}
else {
http_redirect("", array(
section => "info",
message => "Internal error while recieving messages!"
));
}
}
Then I call this. $messageCount
is 2 like it should be because there are two messages for my testuser.
$messages = GetUnreadMessages($userID, $db);
$messageCount = $messages->num_rows; // 2
But when I call this $messages
is always 0. Any idea why?
$message = $messages->fetch_array(MYSQL_ASSOC); // 0