Voting system question
I have a voting system for posts users make where other users can like/dislike
currently is displaying one number. This number is if a user likes, goes to '1' if they dislike goes back down to '0'
$net_vote = $row['votes_up'] - $row['votes_down']; //this is the net result of voting up and voting down
Is this correct? How can i make it so it displays 开发者_JS百科both scores? one for 'like' one for 'dislike'Will display only votes up (likes)
echo 'Likes: '.$row['votes_up'].'<br />';
Will display only votes down (dislikes)
echo 'Dislikes: '.$row['votes_down'].'<br />';
And your current code is correct :)
If I understood you correctly, this will work:
echo "Votes up: " . $row['votes_up'] . "<br />";
echo "Votes down: " . $row['votes_down'] . "<br />";
Assuming there is some database call before hand that assigns $row
as an associative array for the Post in question, using PDO::FETCH_ASSOC
Anyway it should be as simple as:
<p>Current Score: <?php echo $net_vote ?><br />
Likes: <?php echo $row['votes_up'] ?> | Dislikes: <?php echo $row['votes_down'] ?> </p>
The code looks ok, not sure if I thought the problem was simpler if so let me know.
精彩评论