0

so here is my code for like system

<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;

what happen here is if sessionID exists on the DB the if statement will run if not else will... but what happens is after writing this code my button disappear

sql query

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;
  }

also im confuse im in going to use forloop for this??.. any better idea on how to do it...

this button refers to the default icon if the user didn't hit like enter image description here

this button refers to the icon where the user hit like enter image description here

but what happens on the above code is it disappears the button since the button is inside the if statement i dont have any idea on how to do it.. any idea please..

Lion Smith
  • 647
  • 3
  • 16
  • 48
  • I assume you have some javascript with this? Show that too – Qirel Apr 11 '17 at 10:07
  • yeah i do have check this. [link](http://stackoverflow.com/questions/43201495/how-to-stay-the-color-of-the-button-when-hit-like-and-refresh-page) – Lion Smith Apr 11 '17 at 10:49

1 Answers1

0

You are using if else statements inside html wrongly. See this: link

Example:

<? if ($condition): ?>
<p>Content</p>
<? elseif ($other_condition): ?>
<p>Other Content</p>
<? else: ?>
<p>Default Content</p>
<? endif; ?>
Community
  • 1
  • 1
Max Maximilian
  • 591
  • 2
  • 20
  • well this works if i have another condition for it but i dont have.. that is why im using if and else only...elseif is use if you have another condition aside from if but in my condition i dont have so im not using it.. i dont think using just if and else is not a wrong thing.. – Lion Smith Apr 11 '17 at 10:47