这可能需要一些非常基本的东西,但我找不到以我希望它工作的方式执行此操作的答案。我拥有的是一个 mysql 文章表和一个收藏夹表,如果您喜欢一篇文章,则会记录信息。所以我需要从一个表中选择我喜欢的所有文章,然后从另一个表中选择所有文章并将它们全部显示为提要,我已经这样做了。我需要帮助的部分是说,如果我喜欢其中一个帖子,请不要显示“喜欢”按钮(或者,如果我还不喜欢它,请显示该按钮)。谁能指出我正确的方向?这是我拥有的代码,但它只显示了我喜欢的最后一个:
<?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 .= "";
}
}
?>