分享
 
 
 

CSS实现星级评分III

王朝html/css/js·作者佚名  2006-11-24
窄屏简体版  字體: |||超大  

首先是实现的原理

从上一个css实现星级评分I 、II,可是看出,只要能识别onclick和将数据记录至数据库中存储,然后从数据库中调用出数据进行计算就

可以得到当前的评分均值——当前的分值。

1.下面是建立数据库的sql

CREATE TABLE ratings(

id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,

total_votes INT NOT NULL,

total_value INT NOT NULL,

which_id INT NOT NULL,

which_table VARCHAR(255),

used_ips LONGTEXT NULL

);2.参数文件引用

<?php

require("connectDB.php");

require("closeDB.php");

require("tableName.php");

require("openDB.php");

?>

3.显示投票程序和更新投票数据程序

<?php

$rating_posted=$_GET['vote'];//pased variable by the the stars value

$id=$_GET['id'];

$query=mysql_query("SELECT total_votes, total_value, used_ips FROM $tableName WHERE id='".$id."' ")or die(" Error: ".mysql_error());

$numbers=mysql_fetch_assoc($query);

$checkIP=unserialize($numbers['used_ips']);

$count=$numbers['total_votes'];//how many votes total

$current_rating=$numbers['total_value'];//total number of rating added together and stored

$sum=$rating_posted+$current_rating;// add together the current vote value and the total vote value

$tense=($count==1) ? "vote" : "votes";//plural form votes/vote

$voted=@mysql_fetch_assoc(@mysql_query("SELECT title FROM $tableName WHERE used_ips LIKE '%".$_SERVER['REMOTE_ADDR']."%' AND id='$id' ")); //Pattern match ip:suggested by Bramus! http://www.bram.us/ - this variable searches through the previous ip address that have voted and returns true or false

if($voted){

echo "<div class=\"rating\">".

"<ul class=\"star-rating\">".

"<li class=\"current-rating\" style=\"width:". @number_format($current_rating/$count,2)*20 ."px;\">Current rating.</li>".

"<li class=\"one-star\">1</li>".

"<li class=\"two-stars\" >2</li>".

"<li class=\"three-stars\">3</li>".

"<li class=\"four-stars\">4</li>".

"<li class=\"five-stars\">5</li>".

"</ul>".

"<p>Rating: <strong>".@number_format($current_rating/$count,2)."</strong> {".$count." ".$tense." cast} <br />You have previously voted.</p></div>";//show the current value of the vote with the current numbers

}else{

if(isset($_GET['vote'])){

if($sum==0){

$added=0;//checking to see if the first vote has been tallied

}else{

$added=$count+1;//increment the current number of votes

}

if(is_array($checkIP)){

array_push($checkIP,$_SERVER['REMOTE_ADDR']);//if it is an array i.e. already has entries the push in another value

}else{

$checkIP=array($_SERVER['REMOTE_ADDR']);//for the first entry

}

$insert=serialize($checkIP);

mysql_query("UPDATE $tableName SET total_votes='".$added."', total_value='".$sum."', used_ips='".$insert."' WHERE id='".$_GET['id']."'");

echo "<div class=\"rating\"><p>Rating: <strong>".@number_format($sum/$added,2)."</strong> {".$added." ".$tense." cast} <span>Thank you for your vote!</span></p></div>";//show the updated value of the vote

}else{

?>4.访问者评分程序

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>CSS: Star Rater Example</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<link href="styles2-1.css" rel="stylesheet" type="text/css" media="all">

</head>

<body>

<div class="rating">

<p>How clear was this tutorial?</p>

<ul class="star-rating">

<li class="current-rating" style="width:<?php echo @number_format($current_rating/$count,2)*20 ?>px;">Current rating</li>

<li><a href="<?php echo $_SERVER['PHP_SELF'] . "?" .$_GET['section'] . "&amp;id=" . $_GET['id'] . "&amp;vote=1";?>" title="Rate this 1 star out of 5" class="one-star">1</a></li>

<li><a href="<?php echo $_SERVER['PHP_SELF'] . "?" .$_GET['section'] . "&amp;id=" . $_GET['id'] . "&amp;vote=1";?>" title="Rate this 2 stars out of 5" class="two-stars" >2</a></li>

<li><a href="<?php echo $_SERVER['PHP_SELF'] . "?" .$_GET['section'] . "&amp;id=" . $_GET['id'] . "&amp;vote=1";?>" title="Rate this 3 stars out of 5" class="three-stars" >3</a></li>

<li><a href="<?php echo $_SERVER['PHP_SELF'] . "?" .$_GET['section'] . "&amp;id=" . $_GET['id'] . "&amp;vote=1";?>" title="Rate this 4 stars out of 5" class="four-stars" >4</a></li>

<li><a href="<?php echo $_SERVER['PHP_SELF'] . "?" .$_GET['section'] . "&amp;id=" . $_GET['id'] . "&amp;vote=1";?>" title="Rate this 5 stars out of 5" class="five-stars" >5</a></li>

</ul>

</body></html>5.最新评分结果提示

<?php

echo "<p>Rating: <strong>".@number_format($sum/$count,2)."</strong> {".$count." ".$tense." cast}</p></div>";//show the current updated value of the vote

} // end isset get vote

} //end voted true, false

?>下一步是将结果记入数据库,现在没有时间去研究了,请大家等待下一篇文章或者去远出处阅读!

原文:Creating a star rating system part (3)

链接:http://slim.climaxdesigns.com/tutorial.php?id=3

版权:版权归原作者所有,翻译文档版权归本人|greengnn,转载请注明出处www.jluvip.com/blog

我们用php来实现

先看看效果:http://gnn.80x86.cn/starrating

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有