我希望从我的foreach
输出中排除friend_one
或friend_two
中出现的特定值。我不想从我的查询中排除这一点。
要排除的参数为$profile_user
,它出现在friend_one
或friend_two
中。我试图执行此操作if(in_array($friend_total_row->friend_one == $profile_user))
,但我收到错误,而且只有friend_one
。
任何人都知道我该怎么做?
<?php
//Friends --- total
$friend_status = 2;
$friend_sql = "
SELECT *
FROM friends
WHERE (friend_one = :profile_user or friend_two = :profile_user)
AND status = :total_status
";
$friend_stmt = $con->prepare($friend_sql);
$friend_stmt->execute(array(':profile_user' => $profile_user, ':total_status' => $friend_status));
$friend_total_rows = $friend_stmt->fetchAll(PDO::FETCH_ASSOC);
$count_total_friend = $friend_stmt->rowCount();
?>
<div id="friend-list-container">
<div id="friend-list-count">Friends <span class="light-gray"><?php echo $count_total_friend; ?></span></div>
<div id="friend-list-image-container">
<?php
foreach ($friend_total_rows as $friend_total_row) {
if(in_array($friend_total_row->friend_one == $profile_user)) {
continue;
}
else {
$friend_1 = $friend_total_row['friend_one'];
$friend_2 = $friend_total_row['friend_two'];
//$friend_status = $friend_total_row['status'];
//$friend_status_date = $friend_total_row['date'];
}
echo $friend_1 . $friend_2;
}
?>
答案 0 :(得分:1)
更新回答:
b