我想從'posts_fav'抓取最喜歡的帖子,其中帖子ID是行ID。然後我想要它,如果查詢中的用戶標識等於成員標識,它將顯示'是',否則它將顯示'否'。IF語句不起作用
Originial:
foreach ($usersfav as $rowfav) {
if ($rowfav["user_id"] == $member["id"])
{
echo 'yes';
}
else
{
echo 'no';
}
}
我的一個嘗試: 這改變了所有的其他功能。跳過如果因爲需要有一個方法可以讓我得到$ rowfav(「」)的支票,而無需
foreach ($usersfav as $rowfav) {
$sqlfav = "SELECT * FROM posts_fav WHERE post_id = '".$row["id"]."'";
$stmfav = $dbh->prepare($sqlfav);
$stmfav->execute();
$usersfav = $stmfav->fetchAll();
if ($rowfav["user_id"] == $member["id"])
{
echo 'yes';
}
else
{
echo 'no';
}
}
更新: 所以我想在帖裏rowfav [「user_ID的」]和成員[「身份證」]投其所好地說「是」和其他職位沒有,可以發現到說任何行「不」
全碼:
$sql = "
SELECT *,
(SELECT profilepic FROM users WHERE users.username = users_profiles_comments.author) AS profilepic
FROM users_profiles_comments WHERE postid = '". $row["username"] ."' ORDER BY `id` DESC";
$stm = $dbh->prepare($sql);
$stm->execute();
$users = $stm->fetchAll();
foreach ($users as $row) {
echo ' <div class="row user-row">
<div class="col-xs-3 col-sm-2 col-md-2 col-lg-2">
<img class="img-thumbnail"
src="'.$row['profilepic'].'" width="150px;"
alt="User Pic">
</div>
<div class="col-xs-10 col-sm-10 col-md-10 col-lg-10">
<div class="panel panel-default">
<div class="panel-heading"><b>'. $row["author"] .'</b> - <small>'. $row["date"] .'</small>
';
if ($row["author"]) {
echo '<p style="float:right;">';
$sqlfav = "SELECT * FROM posts_fav WHERE post_id = '".$row["id"]."'";
$stmfav = $dbh->prepare($sqlfav);
$stmfav->execute();
$usersfav = $stmfav->fetchAll();
foreach ($usersfav as $rowfav) {
if (strcmp($rowfav["user_id"], $member["id"]) == 0)
{
echo '
Yes
';
}
else {
echo 'No';
} }
@PopoFibo 500服務錯誤。不會工作。 – user3219007
@PopoFibo等待對不起'如果(strcmp($ rowfav [「user_id」],$ member [「id」]))'這是我改變它?這似乎擺脫了這個錯誤。無論如何,這意味着是......的一個是的帖子說不。而表中沒有任何一行的所有其他帖子什麼也沒說。 – user3219007
@PopoFibo更新我的問題的底部,我想做什麼。 – user3219007