0
這可能需要一些非常基本的東西,但我無法按照我希望的方式找到答案。我擁有的是一張mysql表格和一張收藏夾列表,如果你喜歡一篇文章,信息會被記錄下來。因此,我需要從一張表中選擇我喜歡的所有文章,然後選擇所有來自另一張表的文章,並將它們全部顯示爲Feed,我已經完成。我需要幫助的部分是說,如果我喜歡其中一個帖子,不要顯示類似按鈕(或者,如果我還沒有喜歡它,請顯示按鈕)。任何人都可以請用正確的方向指向我嗎?這是我的代碼,但它只顯示最後一個我喜歡:根據多次選擇的結果運行if語句
<?php
$check_like_sql = "SELECT * FROM posts WHERE type = 'Like' && poster = '$yourid'";
$check_like_res = mysqli_query($con, $check_like_sql) or die (mysqli_error());
if(mysqli_affected_rows($con)>0){
while($likes = mysqli_fetch_array($check_like_res)){
$yourlike = $likes['media'];
}
}
?>
<?php
$get_posts_sql = "SELECT posts.*, members.username, members.avatar, fans.connection FROM posts LEFT JOIN members ON members.id = posts.poster LEFT JOIN fans ON fans.fan = '$yourid' WHERE posts.poster = fans.connection ORDER BY date DESC";
$get_posts_res = mysqli_query($con, $get_posts_sql) or die (mysqli_error());
if(mysqli_affected_rows($con)>0){
while($posts = mysqli_fetch_assoc($get_posts_res)){
$postid = $posts['id'];
etc
etc
if($yourlike == $postid){
$likethis = "<a href=\"php/unlike.php?poster=$yourid&post=$postid\">Unlike</a> . ";
}
else if($posttype == "Like"){
$likethis = "";
}
else{
$likethis = "<a href=\"php/like.php?poster=$yourid&lat=$yourlat&lon=$yourlon&like=$postid&user=$postusername\">Like</a> . ";
}
$post .= "";
}
}
?>
你嘗試過什麼嗎? – user20232359723568423357842364
您可以將代碼添加到問題中嗎? – andrewsi
請發佈您的'CREATE TABLE'語句以及您已經嘗試過的內容。 –