【问题标题】:like system check if user like/unlike button喜欢系统检查用户是否喜欢/不喜欢按钮
【发布时间】:2017-09-06 15:44:48
【问题描述】:

所以这是我的类似系统的代码

<div class="btn like"> 
    <div class="boxcoracao">

<?php foreach ($db->checklike($postid,$session_id) as $chk) {
if($postid== $chk['pl_puid'] && $session_id == $chk['pl_uid']){
?>
<input type="hidden" name="likepid" id="likepid" value="<?php echo $postid ?>">
<input type="hidden" name="likemid" id="likemid" value="<?php echo $mem_id ?>">
<span class="coracao ativo" name="like"><br>&emsp;&emsp;&emsp;Love</span> 
<?php
}else{
?>
<input type="hidden" name="likepid" id="likepid" value="<?php echo $postid ?>">
<input type="hidden" name="likemid" id="likemid" value="<?php echo $mem_id ?>">
<span class="coracao" name="like"><br>&emsp;&emsp;&emsp;Love</span> 
    <?php   
        }
    }
    ?>

    </div>
</div>&emsp;&emsp;&emsp;

这里发生的情况是,如果数据库上存在 sessionID,则 if 语句将运行,否则将运行...但是发生的情况是在编写此代码后,我的按钮消失了

sql查询

function checklike($pid,$mid){
        $query = "SELECT * FROM plike WHERE pl_puid = '$pid' AND plc_uid = '$mid'";
        $stmt = $this->dbh->prepare($query);
        $stmt->execute(array("0"));
        $active_data = $stmt->fetchAll(PDO::FETCH_ASSOC);
        return $active_data;
  }

我也很困惑我会为此使用forloop吗??..关于如何做到这一点有更好的想法......

如果用户没有点赞,此按钮指的是默认图标

这个按钮是指用户点击的图标

但是在上面的代码中发生的事情是它消失了按钮,因为按钮在 if 语句中我不知道如何去做.. 请任何想法..

【问题讨论】:

  • 我假设你有一些 javascript?也表明这一点
  • 是的,我确实检查过这个。 link

标签: php mysql


【解决方案1】:

您在 html 中错误地使用了 if else 语句。 看到这个: link

例子:

<? if ($condition): ?>
<p>Content</p>
<? elseif ($other_condition): ?>
<p>Other Content</p>
<? else: ?>
<p>Default Content</p>
<? endif; ?>

【讨论】:

  • 好吧,如果我有其他条件但我没有..这就是为什么我只使用 if 和 else ...elseif 如果你有其他条件,除了 if 但在我的情况下使用条件我没有所以我不使用它..我不认为使用 if 和 else 不是错误的事情..
猜你喜欢
  • 1970-01-01
  • 2018-05-27
  • 2022-12-13
  • 2012-09-20
  • 1970-01-01
  • 1970-01-01
  • 2016-04-04
  • 2014-09-21
  • 2019-07-03
相关资源
最近更新 更多