|
 |
|
มีปัญหาเกี่ยวกับโค๊ต กด Like +1 แบบที่มีอยู่ในเว็บไซต์นี้ไม่ได้ฮะ |
|
 |
|
|
 |
 |
|
คืออยากเมื่อทำการกดปุ่ม ถูกใจ+1 ก็จะนำเลขเดิมที่มีอยู่ในฐานข้อมูลออกมา +1 เช่น 4+1=5 แล้วแสดงเป็นเลข 5 หลังจากกด ดังตัวอย่าง
[ ถูกใจ +1] Lile 4 เมื่อคลิกแล้วก็จะแสดงเป็น [ ถูกใจ +1] Like 5 ทันที่
ฐานข้อมูลมี
id int 7
counter int 7
test.php
ทดสอบการกด Like
<script>
// Jquery
$(document).ready(function(){
$("#add").live("click",function(){
$.ajax({
url:"like.php",
type:"POST",
data:"id=1",
success:function(res){
$("span.like").html(res);
},
error:function(err){
alert("error : "+err);
}
});
});
});
</script>
<span class='like'></span> <a href='#' id="add">[ถูกใจ +1]</a>
like.php
Add_Like)
<?
$host="localhost";
$username="root"; // ชื่อผู้ใช้
$pass_word="1234"; // รหัสผ่าน
$db="web_like"; // ชื่อ ฐานข้อมูล
// ติดต่อฐานข้อมูล
mysql_connect( $host,$username,$pass_word) or die ("ติดต่อ Mysql ไม่ได้ ");
mysql_db_query($db,"SET NAMES UTF8");
mysql_select_db($db) or die("เลือกข้อมูลไม่ได้");
$update=mysql_query("UPDATE tb_counter set counter=counter+1 where id='".$_POST['id']."'");
if($update)
{
$sql="Select * from tb_counter where id='".$_POST['id']."'";
$rs=mysql_query($sql);
$f=mysql_fetch_array($rs);
echo $f['counter'];
}
?>
ช่วยดูให้ทีฮะ ว่าผิดตรงไหน เพราะกดแล้วนิ่งฮะ ไม่มีอะไรเข้าฐานข้อมูลเลย และไม่โชว์ตัวเลขที่บวกแล้วด้วย
Tag : PHP, MySQL, JavaScript, Ajax

|
|
 |
 |
 |
 |
Date :
2011-12-22 18:43:12 |
By :
Omaha |
View :
915 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็ใช้วิธีนี้ดูก่อนนะ
คือ select ข้อมูลของฟิลด์ like ออกมาแล้วก็สร้างตัวแปรเก็บค่ามันไว้
จากนั้นก็ให้ตัวแปรบวกค่าเอาไปหนึ่ง แล้วก็เอาไปอัพเดทน่ะ
ลองดูนะ
|
 |
 |
 |
 |
Date :
2011-12-22 22:58:42 |
By :
บังเอิญผ่านมาเห็น |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
??? คือจากโค๊ตข้างบน มันใช้ไม่ได้ฮะ เลยยกโค๊ตมาให้ช่วยดูกันฮะ ว่าจะแก้ไขยังไง เพราะทำไปทำมาเริ่มมั่วฮะ ดูเหมือนจะง่ายแต่ยากเฉยเลย หรือว่าคิดลึกไปไม่รู้ วานผู้ใจบุญช่วยแก้ไขทีฮะ ว่าเชื่อมต่อฐานข้อมูลผิดหรือว่าคิวรี่ผิดเลยบันทึกไม่ได้และแสดงผล +1 ไม่ได้ อยากให้ได้ฮะ จะได้เป็นความรู้ให้คนอื่นที่สนใจด้วย ขอบคุณทุกความช่วยเหลือฮะ 
|
 |
 |
 |
 |
Date :
2011-12-22 23:11:25 |
By :
Omaha |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|