大家好,我有两张桌子,第一个桌子叫做“帖子”,看起来像这样
id picture title description poster ip posterid .....
123 img-2.jpg Title 1 Desc 1 Poster xx 1
第二个表叫“爱”,长这个样子
id ip userid postid created
1 xx 1 123 date
这是我的 MySQL 查询的实际外观:
<?php
// Get records from the database
$query = $db->query("SELECT * FROM posts ORDER BY id DESC LIMIT 10");
if($query->num_rows > 0){
while($row = $query->fetch_assoc()){
$postID = $row['id'];
?>
<!-- POST ITEM START -->
<div class="post-item">
<div class="post-asset image">
<img src="uploads/<?php echo $row['picture']; ?>">
</div>
<div class="post-header">
<h3 class="post-title"><a href="#" data-loader="show"><?php echo $row['title']; ?></a></h3>
<span class="post-category">
<a class="favorite-button" href="#" data-post="<?php echo $row['id']; ?>" data-userid="<?php echo $_SESSION['user_id'];?>"><span class="favorite-button-icon fa fa-star-o"></span></a>
</span>
<span class="post-date font17"><i class="fa fa-clock-o"></i> <?php $timeago=get_timeago(strtotime($row['created'])); echo $timeago;?></span>
<span class="post-comments font17"><i class="fa fa-comments-o"></i> 1,3k Reaktionen</span>
</div>
<div class="post-footer">
<a href="#" class="post-author">
<span class="author-img"><img src="img/avatar.png"></span>
<span class="author-name">OnePost von<b><?php echo $row['poster']; ?></b></span>
我现在想要做的是了解具有其会话 ID(也是用户 ID)的实际用户是否喜欢该帖子,并在是否喜欢该帖子时显示它。
红糖糍粑