index.html

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>演示:PHP+jQuery+MySql实现的“顶”和“踩”功能</title>
<meta name="keywords" content="PHP,mysql,jquery" />
<meta name="description" content="Helloweba演示平台,演示XHTML、CSS、jquery、PHP案例和示例" />
<link rel="stylesheet" type="text/css" href="main.css" />
<style type="text/css">
.digg{width:420px; height:120px; margin:80px auto 20px auto; position:relative}
#dig_up,#dig_down{width:200px; height:48px; margin:10px; position:relative; border:1px solid #d3d3d3; padding-left:42px; cursor:pointer}
.digup{background:url(diggs.png) no-repeat 4px 2px;}
.digup_on{background:url(diggs.png) no-repeat 4px -49px;}
.digdown{background:url(diggs.png) no-repeat 4px -102px;}
.digdown_on{background:url(diggs.png) no-repeat 4px -154px;}
#num_up,#num_down{position:absolute; right:6px; top:18px; font-size:20px;}
#dig_up p{height:24px; line-height:24px; color:#360}
#dig_down p{height:24px; line-height:24px; color:#f30}
.bar{width:100px; height:12px; line-height:12px; border:1px solid #f0f0f0; position:relative; text-align:center}
.bar span{display:block; height:12px; }
.bar i{position:absolute; top:0; left:104px;}
#bar_up span{background:#360}
#bar_down span{background:#f60}
#msg{position:absolute; right:20px; top:40px; font-size:18px; color:#f00}
</style>
</head>

<body>


<div );
}
});
}
</script>

</html>

do.php

<?php
include_once("connect.php");

$action = $_GET['action'];
$id = 1;
$ip = get_client_ip();

if($action=='like'){
likes(1,$id,$ip);
}elseif($action=='unlike'){
likes(0,$id,$ip);
}else{
echo jsons($id);
}

function likes($type,$id,$ip){
$ip_sql=mysql_query("select ip from votes_ip where vid='$id' and ip='$ip'");
$count=mysql_num_rows($ip_sql);
if($count==0){//还没有顶过
if($type==1){//顶
$sql = "update votes set likes=likes+1 where ;
return ($ip);
}
?>

connect.php

<?php
//数据库配置
$host="localhost";
$db_user="root";//用户名
$db_pass="1234567890";//密码
$db_name="vote";//数据库名
$timezone="Asia/Shanghai";

$link=mysql_connect($host,$db_user,$db_pass);
mysql_select_db($db_name,$link);
mysql_query("SET names UTF8");

header("Content-Type: text/html; charset=utf-8");
?>

main.css,images/ 略

详见 http://www.helloweba.com/view-blog-237.html

相关文章:

  • 2021-12-14
  • 2021-09-01
  • 2021-05-17
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
  • 2021-07-07
  • 2021-05-30
  • 2022-12-23
相关资源
相似解决方案