使用下面的代码,我显示状态和评论,它按需要工作,虽然我不完全理解我自己的代码..
我想实现以下目标:如果结果来自状态,$link_type = status,如果结果来自评论,$link_type = 评论
这是我的尝试($link_type 现在总是“状态”)
$results = db_query("
SELECT sid as ssid, created as screated, message as smessage, recipient as srecipient
FROM {statuses}
WHERE created > :logout_stamp
UNION
SELECT sid as ssid, created as screated, comment as smessage, uid as srecipient
FROM {fbss_comments} fbss
WHERE fbss.created > :logout_stamp
ORDER BY screated DESC LIMIT 15",
array(':logout_stamp' => $logout_stamp))->fetchAll();
// foreach the results
foreach ($results as $result) {
$user_status = user_load($result->srecipient);
$user_comment = user_load($result->commentuid);
$username_status = $user_status->name;
$username_comment = $user_comment->name;
$date_status = $result->screated;
$date_comment = $result->commentcreated;
if ($result->ccreated != NULL) {
$link_type = "comment";
}
else {
$link_type = "status";
}
print '<a href="statuses/' . ($result->ssid) . '" class="notification_wrapper">' . '<b>' . $username_status . '</b>' . ' - ' . ($link_type) . ' - ' . strip_tags(substr($result->smessage,0,30)) . ' - ' . elapsed_time($date_status) . '</a>';
非常感谢您的建议