gpt4 book ai didi

php - 仅获取一个通知结果

转载 作者:行者123 更新时间:2023-11-29 12:50:30 24 4
gpt4 key购买 nike

所以我有一个通知系统,这是表格布局

+-----------+------------------+------+-----+---------+----------------+
| 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 | |
+-----------+------------------+------+-----+---------+----------------+

这就是一行的样子

+----+-----------+---------+--------+------+
| id | from_user | to_user | type | date |
+----+-----------+---------+--------+------+
| 32 | allex | scott | hgjghj | NULL |
+----+-----------+---------+--------+------+

现在这是我获得结果的方式

    //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']
);
}

现在最后是我的问题,假设我有另一行,并且类型不同,发生的情况是一旦我循环查询,我会在整个查询中得到相同的 type 返回,所以而不是

Alelx hgjghj scott,

并说我有另一个结果

Alelx ghfjhgj scott

我无法看到它,因为第一个结果中的Type最终成为“主导”。任何帮助都会很棒。

最佳答案

根据您的代码,您的 $notifications 数组将如下所示:

Array
0 => (... type=>'hgjghj' ...)
1 => (... type=>'ghfjhgj' ...)

数据库的每一行都会向该数组获取另一个元素。因此,您需要循环遍历该数组并查看获得的值。

关于php - 仅获取一个通知结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24813635/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com