如果我的三元运算符返回为真,我试图显示一种颜色,如果返回为假,则显示另一种颜色。操作员正在工作,但有一件事发生了。双引号内的代码显示而不是实际颜色本身。有人知道怎么修这个东西吗 ?
$msg .= ($row['opened'] == '0') ? "background-color: #DDEDFF;" : "background-color: #000000;";
编辑!!!$msg- 这是我的变量唯一出现的时间
public function getLatestMessage ($userLoggedIn, $user2) {
$query = $this->con->prepare('SELECT body, user_to, opened, date FROM messages WHERE
user_to = ? AND user_from = ? OR user_to = ? AND user_from = ? ORDER BY id DESC LIMIT 1');
$query->bind_param("ssss", $userLoggedIn, $user2, $user2, $userLoggedIn);
$query->execute();
$query_result = $query->get_result();
$msg = ""; //to hold the message data
if ($row = $query_result->fetch_assoc()) { //don't need a while here because we've limited the query to one record
//Timeframe
$date_time_now = date("Y-m-d H:i:s");
$start_date = new DateTime($row['date']); //Time of post
$end_date = new DateTime($date_time_now); //Current time
$interval = $start_date->diff($end_date); //Difference between dates
if($interval->y >= 1) {
if($interval->y == 1)
$time_message = $interval->y . "yr"; //1 year ago
else
$time_message = $interval->y . "yrs"; //1+ year ago
}
else if ($interval-> m >= 1) {
if($interval->d == 0) {
$days = " ago";
}
else if($interval->d == 1) {
$days = $interval->d . "d";
}
else {
$days = $interval->d . "d";
}
if($interval->m == 1) {
$time_message = $interval->m . "month";
}
else {
$time_message = $interval->m . "months";
}
}
繁星coding