I need to get a like button for each post, so that each time the while returns results each of those results has a like button unique to them, the issue I am having right now if the person can vote for one, but that's it, and all the other seperate posts are blocked off because they already voted, any advice? If you need referral to what I am trying to have the like system like I need it to be like this sites. http://fmylife.com/ their structure is the formum like I am looking for
while($row = $stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<div class="wrapper">
<div class="submissions">
<div class="logo-logo"><h2>Quotr.</h2>
<div class="checkboxes">
<?php echo htmlentities($row["formtype"]); ?>
</div>
</div>
<div class="top-submit">
“<?php echo htmlentities($row["actual_quote"]); ?>”
</div>
<div class="poster">
- <?php
echo htmlentities($row["poster"]);
if(isset($row3["voted"]) && isset($row3["ip"]))
{
echo "You have already voted for this.";
}
else
{
?>
<form action="" method="post">
<input type="submit" name="like" value="like" />
<input type="submit" name="dislike" value="dislike" />
</form>
<?php
}
?>
<div class="like"></div>
<div class="dislike"></div>
</div>
<!-- use select to get the items to stay on the page-->
</div>
</div>
<?php
}
?>
And here's the code for the like button/dislike:
$likes = (empty($_POST['like'])) ? : $_POST['like'] ;
$dislikes = (empty($_POST['dislike'])) ? : $_POST['dislike'] ;
$ip = $_SERVER['REMOTE_ADDR'];
if(isset($_POST['like'])){
$likes1 = $likes+1;
$voted1 = $voted+1;
$query2 = $db->prepare("INSERT INTO voters (voted, ip) VALUES ( :voted, :ip)");
$query2->bindParam(':voted', $voted1, PDO::PARAM_STR);
$query2->bindParam(':ip', $ip, PDO::PARAM_STR);
$query2->execute();
header("Location: like.php?");
$update1 = $db->prepare("INSERT INTO votes (likes) VALUES ( :likes)");
$update1->bindParam(':likes', $likes1, PDO::PARAM_STR);
$update1->execute();
}
if(isset($_POST['dislike'])){
$dislikes1 = $dislikes+1;
$voted1 = $voted+1;
$query2 = $db->prepare("INSERT INTO voters (voted, ip) VALUES ( :voted, :ip)");
$query2->bindParam(':voted', $voted1, PDO::PARAM_STR);
$query2->bindParam(':ip', $ip, PDO::PARAM_STR);
$query2->execute();
header("Location: like.php?");
$update1 = $db->prepare("INSERT INTO votes (dislikes) VALUES ( :dislikes)");
$update1->bindParam(':dislikes', $dislikes1, PDO::PARAM_STR);
$update1->execute();
}
$stmt = $db->query("SELECT * FROM voters");
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$row3 = $stmt->fetch();