here is the problems 红色突出显示:问题(我认为) 蓝色突出显示:工作正常
这是我目前面临的问题 Current situation 标签列表未显示从数据库表中获取结果标签的值
真实标签列表视图必须像这样 enter image description here 例如:a是从数据库获取结果中的值
在添加此$ fetch_label = array(); *后突出显示黄色 就像在我给的图像中一样,未分类的标签值正在显示,但是我之前添加的其他标签并没有显示它只是显示空白标签,请帮助我。 我的完整代码预览
elseif ($request == 'get_notifications') {
if ($auth) {
if (getdb()) {
$db = pg_connect($conn_string);
$get_notifications = pg_prepare($db, "get_notifications", "select n.*, coalesce(lbl.labelname, 'Uncategorized') as labelname from public.notifications n
left join (
select * from public.notif_label nl
inner join public.label l on (nl.id_lbl = l.id and l.id_user = $1)
) lbl on (lbl.id_notif = n.id_notif)
where n.userid = $2 AND n.isdeleted = false AND n.notificationdate >= DATE(NOW()) - INTERVAL '7' DAY
ORDER BY n.notificationdate desc");
$get_notifications = pg_execute($db, "get_notifications", array($auth->id, $auth->id));
$fetch_notif = pg_fetch_all($get_notifications);
$map_date = array_map(function($o) { return substr($o['notificationdate'], 0, 10); }, $fetch_notif);
$unique_date = array_unique($map_date);
$fetch_label = array();
$get_user_label = pg_prepare($db, "get_user_label", "SELECT id, labelname FROM public.label WHERE id_user = $1");
$get_user_label = pg_execute($db, "get_user_label", array($auth->id));
$label_result = pg_fetch_all($get_user_label);
if ($label_result) {
array_push($fetch_label, $label_result);
}
array_push($fetch_label, array('id' => 9999, 'labelname' => 'Uncategorized'));
$transformed_results = array();
foreach ($unique_date as $header) {
$labelList = array();
foreach ($fetch_label as $label) {
$notifs = array_values(array_filter($fetch_notif, function($elem) use($header, $label){
return (substr($elem['notificationdate'], 0, 10) == $header && $elem['labelname'] == $label['labelname']);
}));
array_push($labelList, array('labelname' => $label['labelname'], 'expanded' => false, 'notifs' => $notifs));
}
array_push($transformed_results, array('key' => $header, 'expanded' => false, 'labelList' => $labelList));
}
$notifications = json_encode(array('notifications' => $transformed_results));
pg_close();
echo $notifications;
} else {
echo "Connection failed";
}
} else {
echo "Not authorized";
}
}