Last 15 Snips show! Welcome to Snipped, a code gallery for creating, saving and sharing all kinds of code snippets.

Voting Like/Unlike Feature, PHP Funktion, jQuery,

PHP · April 29, 2016 8:02 am

0 0 574

Speichert Likes bei klick ähnlich wie der Like Funktion hier. Fehlt nur die IP Sperre

<span id="voted-1" class="snip-voted btn">123</span>
<span class="glyphicon glyphicon-thumbs-up vote-top" voteid="1" aria-hidden="true"></span>
<span class="glyphicon glyphicon-thumbs-down vote-down" voteid="1" aria-hidden="true"></span>

<script>
// Voting top
$(".vote-top").click(function(){
var id_top = $( this ).attr( "voteid" );
$.get( "ajax.php?voting_id="+id_top+"&voting_up=1", function( data ) {

var dholeidd = 'voted-'+id_top;
var ddownalt = $('#'+dholeidd).text();
var dergebniss = +ddownalt + 1;
$('#'+dholeidd).text(dergebniss);

});
});

// Voting up
$(".vote-down").click(function(){
var id_down = $( this ).attr( "voteid" );
$.get( "ajax.php?voting_id="+id_down+"&voting_down=1", function( data ) {
var holeidd = 'voted-'+id_down;
var downalt = $('#'+holeidd).text();
var ergebniss = downalt - 1;
$('#'+holeidd).text(ergebniss);
});

});
</script>

<?php

/* Save in DB + 1 on voting and +1 on counting
*/
if (isset($_GET['voting_id']) AND isset($_GET['voting_up'])) {

$id = $_GET['voting_id'];
$sql = "UPDATE snippets SET vote = vote+1, vote_count = vote_count+1 WHERE id = :id";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':id', $id, PDO::PARAM_STR);
$stmt->execute();
header('Content-Type: application/json');
$data = "1";
echo $data;

}

/* Save in DB - 1 on voting and +1 on counting
*/
if (isset($_GET['voting_id']) AND isset($_GET['voting_down'])) {

$id = $_GET['voting_id'];

$sql = "UPDATE snippets SET vote = vote-1, vote_count = vote_count+1 WHERE id = :id";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':id', $id, PDO::PARAM_STR);
$stmt->execute();

header('Content-Type: application/json');
$data = "1";
echo $data;

}

?>

Discuss this Snip
    No Discussion Comments found.

    You must be Signed In to discuss this Snip
Chris

Chris

Joined on
April 28, 2016

  • 22 Snips
    Contributed
  • 19 Likes
    Given
  • 8 Comments Posted
Snip Tags
Get Social And Share

Manage and share all of your code snippets in one easy place.