1 回答
TA贡献1864条经验 获得超6个赞
这个问题是由于每次迭代中的 $color 覆盖而发生的。
尝试这个:
$i = 0;
while ($row = $query_result->fetch_assoc()) {
$user_to_push = ($row['user_to'] != $userLoggedIn) ? $row['user_to'] : $row['user_from'];
if(!in_array($user_to_push, $convos)) {
array_push($convos, $user_to_push);
}
$color[$i] = ($row['opened'] == '0') ? "#DDEDFF" : "";
$i++;
}
foreach ($convos as $key => $username) {
$user_found_obj = new User($this->con, $username);
$latest_message_details = $this->getLatestMessage($userLoggedIn, $username);
$return_string .= "<a href='messages.php?u=$username'><div class='user_found_messages'
style='background-color: ". $color[$key]; ."' >
<img src='" . $user_found_obj->getProfilePic() .
"' style='border-radius: 5px; margin-right: 5px;'>
". $username ."<br/>".
$latest_message_details . "</div></a>";
}
- 1 回答
- 0 关注
- 100 浏览
添加回答
举报