我之前问过这个问题并得到了答案,但我想做一些不同的事情。我正在创建一个社交网站,让人们可以互相发送消息。opened如果列是,我想用蓝色背景显示 div == 0。但我现在只显示 else 列中的 div,该列是空白的。
因此,即使条件成立并且背景颜色应该显示蓝色,背景颜色也会立即直接变为其他颜色。有什么帮助吗?
public function getConvos () {
$userLoggedIn = $this->user_obj->getUsername();
$return_string = "";
$convos = array();
$query = $this->con->prepare('SELECT user_to, user_from, opened FROM messages WHERE
user_to = ? OR user_from = ? ORDER BY id DESC');
$query->bind_param("ss", $userLoggedIn, $userLoggedIn);
$query->execute();
$query_result = $query->get_result();
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 = ($row['opened'] == '0') ? "#DDEDFF" : "";
}
foreach ($convos as $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;' >
<img src='" . $user_found_obj->getProfilePic() .
"' style='border-radius: 5px; margin-right: 5px;'>
". $username ."<br/>".
$latest_message_details . "</div></a>";
}
return $return_string;
}
.user_found_messages {
padding-left: 10px;
padding-top: 20px;
padding-bottom: 10px;
height: auto;
border-bottom: 1px solid #d9d9d9;
}
.user_found_messages:hover {
background-color: #e6ffff;
color: #669999;
}
.user_found_messages img {
height: 105px;
float: left;
margin-top: 1px;
margin-right: 5px;
}
慕尼黑的夜晚无繁华