喜欢系统检查用户喜欢/不喜欢按钮

时间:2017-04-11 10:03:34

标签: php mysql

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

<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这个??有任何更好的想法如何做...

如果用户没有点击,则此按钮引用默认图标 enter image description here

此按钮指的是用户点击的图标 enter image description here

但上面的代码会发生什么,它会消失按钮,因为按钮在if语句中我不知道怎么做...任何想法请...

1 个答案:

答案 0 :(得分:0)

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

示例:

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