php+sqlite+ajax给指定id的数据点赞


demo-ajax-click.html文件如下
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="http://blog.1500km.com/sites/ui-blog/other/favicon.ico" rel="shortcut icon" />
<link href="http://blog.1500km.com/sites/ui-blog/other/favicon.ico" rel=bookmark />

<style>  
hr{ border-bottom:dashed 1px #ccc; border-top:solid 0px #ccc;}
.btn{ background-color:#339933; color:#FFFFFF; padding:3px;}  
body{ font-size:12px; color:#666;}
</style>  

<script type="text/javascript" src="http://blog.1500km.com/sites/ui-blog/other/jquery.js"></script>
<script type="text/javascript">
function ajax_click(id){
  var url='/sites/ui-blog/other/demo-ajax-click-data.php?id='+id;
  $.getJSON(url,function(data){
    var id=data.id;
    var clickx=data.clickx;
    $("#id").html('<hr>id='+id);
    $("#clickx").html('<hr>'+clickx);
  });
}

$(document).ajaxStart(function(){ 
  $("#loading").show(); 
}).ajaxStop(function(){ 
  $("#loading").hide(); 
});
</script>

<img src="http://blog.1500km.com/sites/download/images/1500km.png" style="vertical-align:middle;" />php+sqlite+ajax给指定id的数据点赞<hr>

<input type="button" class="btn" value="给id=1的数据点赞" onClick="ajax_click(1)">
<input type="button" class="btn" value="给id=2的数据点赞" onClick="ajax_click(2)">
<input type="button" class="btn" value="给id=3的数据点赞" onClick="ajax_click(3)">


<span id="id"></span>
<span id="clickx" style="font-size:155px;"></span>

<div id="loading" style="display:none">
<img src="http://blog.1500km.com/sites/ui-blog/other/loading.gif">
</div> 

<br><br>
<a target="_blank" href="http://www.1500km.com">返回1500km</a>

demo-ajax-click-data.php文件如下
<?    
$conn = new SQLiteDatabase('test.db');    
$id= (int) isset($_GET['id']) ? $_GET['id'] : 1;

if($id<1 || $id>29){
  $id=1;
}

$sql = "update www_1500km_com set clickx=clickx+1 where id=$id ";
$x = $conn->query($sql);


$sql = "select id,clickx from www_1500km_com where id=$id";
$x = $conn->arrayQuery($sql);
$d = $x[0];


$a=array('id'=>$d['id'],'clickx'=>$d['clickx']);
echo json_encode($a);
?>

程序运行结果如下图所示,点击这里亲自运行看看