Je cherche des exemples d'implémentation d'un système de vote StackOverflow/reddit en php.Système de vote Stack Overflow/reddit en php
Fondamentalement, je veux les flèches haut et bas. Y a-t-il de bons exemples?
Je cherche des exemples d'implémentation d'un système de vote StackOverflow/reddit en php.Système de vote Stack Overflow/reddit en php
Fondamentalement, je veux les flèches haut et bas. Y a-t-il de bons exemples?
Il y a beaucoup de scripts out there mais ce n'est pas trop difficile à faire soi-même.
J'ai utilisé jQuery (pour gérer AJAX) et un petit script PHP auparavant. Par exemple, certains pseudo-code:
// Some checking for recent votes from this user is appropriate here
if (isset($_POST['voteType'], $_POST['postId']) && $user->loggedIn) {
// insert vote into database if not already inserted
echo json_encode(array('error' => false));
} else {
// bad request/hack attempt
echo json_encode(array('error' => true, 'message' => 'Bad parameters sent'));
}
puis certains jQuery:
$('#upVote').click(function() {
$.post('vote.php', {voteType: 'up', postId: 42}, 'updateIcon(data, textStatus)', 'json');
});
function updateIcon(data, textStatus) {
// If error = false highlight the upvote icon
// else show the error message returned
}
Vous pouvez utiliser celui-ci: http://www.technabled.com/2011/02/pulse-lite-reddit-ajax-up-down-voting.html Divulgation: Je suis le développeur.