[英]Getting only one notification result
So I have a notification system, here's the tables layout 所以我有一个通知系统,这是表格的布局
+-----------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+------------------+------+-----+---------+----------------+
| id | int(11) unsigned | NO | PRI | NULL | auto_increment |
| from_user | varchar(255) | YES | | NULL | |
| to_user | varchar(255) | YES | | NULL | |
| type | varchar(255) | YES | | NULL | |
| date | varchar(255) | YES | | NULL | |
+-----------+------------------+------+-----+---------+----------------+
And this is what one row looks like 这就是一排的样子
+----+-----------+---------+--------+------+
| id | from_user | to_user | type | date |
+----+-----------+---------+--------+------+
| 32 | allex | scott | hgjghj | NULL |
+----+-----------+---------+--------+------+
Now here's how I'm getting the results 现在这就是我得到结果的方式
//Check if any records of notifications exists & loop em' back
$stmt = $con->prepare("SELECT * FROM notifications WHERE to_user = :user");
$stmt->bindValue(':user', $username, PDO::PARAM_STR);
$stmt->execute();
$notifications = array();
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
$notifications[] = array(
'id' => $row['id'],
'from_user' => $row['from_user'],
'to_user' => $row['to_user'],
'type' => $row['type'],
'date' => $row['date']
);
}
And now finally my issue, say I had another row, and the type was different, what happens is once I loop the query I get the same type
returned throughout the whole, so instead of 现在终于我的问题,说我有另一行,类型不同,发生的事情是有一次我循环查询我得到同样的type
在整个返回,所以不是
Alelx hgjghj scott,
and say I had another result that said 说我还有另一个结果
Alelx ghfjhgj scott
I wouldn't be able to see it because the Type
from the first result ends up being "dominant". 我看不到它,因为第一个结果的Type
最终是“显性”的。 Any help would be great. 任何帮助都会很棒。
According to your code your $notifications array will look like this: 根据您的代码,您的$ notifications数组将如下所示:
Array
0 => (... type=>'hgjghj' ...)
1 => (... type=>'ghfjhgj' ...)
Every row of your DB will get another element to this array. 数据库的每一行都会为该数组添加另一个元素。 So, you need to loop through that array and see what values you get. 因此,您需要遍历该数组并查看获得的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.