• 20-07-2013, 16:53:40
    #1
    JS
    function vote_up(){ 
        $("a.vote_up").click(function(){ 
        the_id = $(this).attr('id'); 
        $(this).parent().html("<img src='" + home + "/img/spinner.gif'/>"); 
        $("span#votes_count"+the_id).fadeOut("fast"); 
            $.ajax({ 
                type: "POST", 
                data: "action=vote_up&id="+$(this).attr("id"), 
                url: home + "/ajax.php", 
                success: function(msg) 
                { 
                    $("span#votes_count"+the_id).html(msg); 
                    $("span#votes_count"+the_id).fadeIn(); 
                    $("span#vote_buttons"+the_id).remove(); 
                },  
                error: function(msg) {  
                    $.msgBox({ title: "Uyarı", content: 'Oylama Sırasında Hata Meydana Geldi!'});  
                }  
            }); 
        }); 
    } 
    function vote_down(){     
        $("a.vote_down").click(function(){ 
        the_id = $(this).attr('id'); 
        $(this).parent().html("<img src='" + home + "/img/spinner.gif'/>"); 
            $.ajax({ 
                type: "POST", 
                data: "action=vote_down&id="+$(this).attr("id"), 
                url: home + "/ajax.php", 
                success: function(msg) 
                { 
                    $("span#votes_count"+the_id).fadeOut(); 
                    $("span#votes_count"+the_id).html(msg); 
                    $("span#votes_count"+the_id).fadeIn(); 
                    $("span#vote_buttons"+the_id).remove(); 
                },  
                error: function(msg) {  
                    $.msgBox({ title: "Uyarı", content: 'Oylama Sırasında Hata Meydana Geldi!'});  
                }  
            }); 
        }); 
    }
    PHP
    if(isset($_POST["action"])){
    $id = $_POST["id"];
    $action = $_POST["action"];
    $cur_votes = getAllVotes($id);
    if($action=="vote_up")
    {
    	$votes_up = $cur_votes[0]+1;
    	$q = "UPDATE comments SET votes_up = $votes_up WHERE id = $id";
    }
    elseif($action=="vote_down")
    {
    	$votes_down = $cur_votes[1]+1;
    	$q = "UPDATE comments SET votes_down = $votes_down WHERE id = $id";
    }
    
    $r = mysql_query($q);
    if($r)
    	{
    	$effectiveVote = getEffectiveVotes($id);
    	echo $effectiveVote." Oy";
    	}
    elseif(!$r)
    	{
    	echo "Hata!";
    	}
    }
    Bu kodda nerde hata var ?

    Jquery ilk tıklamama tetiklemiyor, ikinci tıklamaya tetikliyor.
    O da şu sorunu yaratıyor.
    Örneğin a makalesinin oylaması 18 olsun.
    Ben bu makaleye olumsuz oylama vereceğim.
    Verdiğim zaman jquery 2.kez tetiklediği için 16 oylamaya düşüyor.
    Sorun nerede acep ?
  • 21-07-2013, 01:05:20
    #2
    Üyeliği durduruldu
    If elseif kontrollerinden kaynaklaniyor gibi elseif kullanma

    Samsung Galaxy S3 tapatalk 2 ile gonderildi.
    Yazim yanlislari varsa affola.
  • 21-07-2013, 02:34:03
    #3
    Quismo adlı üyeden alıntı: mesajı görüntüle
    If elseif kontrollerinden kaynaklaniyor gibi elseif kullanma

    Samsung Galaxy S3 tapatalk 2 ile gonderildi.
    Yazim yanlislari varsa affola.
    elseif kullanmasam da aynı sorun devam ediyor.

    kod bloğu içindeki fonksiyonlar
    ## Vote ##
    function getAllVotes($id)
    	{
    	$votes = array();
    	$q = "SELECT * FROM comments WHERE id = $id";
    	$r = mysql_query($q);
    	if(mysql_num_rows($r)==1)
    		{
    		$row = mysql_fetch_assoc($r);
    		$votes[0] = $row['votes_up'];
    		$votes[1] = $row['votes_down'];
    		}
    	return $votes;
    	}
    
    function getEffectiveVotes($id)
    	{
    	$votes = getAllVotes($id);
    	$effectiveVote = $votes[0]." Like, ".$votes[1]." Dislike";
    	return $effectiveVote;
    	}
    ## Vote ##