I am trying to get all the messages that have not been read by the logged in user to display the number of unread message notifications.
But for some unknown reason this is not getting any results from the database. At first I thought it was an error in my code and I tried to consult my SQL query in phpMyAdmin and it throws me the error, for that reason I think the error is in my SQL statement .
This is what it is showing me on my screen:
My SQL statement:
<?php
// sacar todos los usuarios registrados recientemente
$stetament = $conexion->prepare(
"SELECT id_messege, COUNT(id_messege) AS countNoti FROM messege WHERE view 'No' AND id_receptor = $id"
);
$stetament->execute(array());
while ($result = $stetament->fetch()) {
// cantidad de Productos publicados
$noti = $row['countNoti'];
}
var_dump($noti);
What I want to achieve as I said before is to get the number of messages not read by the user who is connected. The ID of the user that is connected is stored in a variable calls $id
and the messages that have not been read are whenview = 'No'
NOTE: the file notificacion.php
contains the SQL code above and line 14 is where it says:var_dump($noti);
The problem is based on the fact that in your SQL query you are not placing the letter of equals to check if
view = 'No'
.On the other hand, as I already mentioned in the comments,
view
it is an SQL reserved word and therefore you must add it between 2 I accept you record to avoid having a problem with your SQL statement