|
|
|
ขอคำแนะนำทีครับ พอจะมีตัวอย่าง การให้ Rating Star แบบเป็นบทความไหมครับ |
|
|
|
|
|
|
|
ประมาณแบบนี้ครับ จะให้คะแนนแต่ละตัวยังไงหรอครับ
หรือ พอจะมีตัวอย่าง codeการให้ rating แบบของเว็บ thaicreate นี้ไหมครับ
ขอบคุณครับ -/\-
Code (PHP)
<?php
session_start();
if($_SESSION['username'] =="" )
{
echo "please Login";
echo "<meta http-equiv='refresh' content='2;URL=index.php'>";
exit();
}
if(!$_SESSION["adminid"])
{
echo "Admin only";
echo "<meta http-equiv='refresh' content='2;URL=index.php'>";
exit();
}
include("config.inc.php");
$SQL = "SELECT * FROM useradmin WHERE username = '".$_SESSION['username']."' ";
$QRY = mysql_query($SQL);
$RS = mysql_fetch_array($QRY);
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Main Admin</title>
<link rel="stylesheet" href="admin_menu2_files/css3menu1/style.css" type="text/css" /><style type="text/css">._css3m{display:none}</style>
<style type="text/css">
._css3m {
display:none
}
.edit form table tr td #SAVE {
text-align: center;
}
.edit form table tr td #Reset {
text-align: center;
}
.edit form table tr td {
text-align: center;
}
.edit form table {
text-align: right;
}
body {
background-image: url(images/food_pasta_desktop_3357x2536_hd-wallpaper-482867.jpg);
}
</style>
<!-- rate Star-->
<style>
body{
font:12px Arial, Helvetica, sans-serif;
padding:40px;
}
</style>
<script src="rating/jquery.min.js" type="text/javascript"></script>
<script src="rating/starrating.js" type="text/javascript"></script>
<link href="rating/starrating.css" rel="stylesheet" type="text/css" media="screen" />
</head>
<body><center>
<img src="logo.gif" width="270" height="102" border="0" usemap="#Map">
<map name="Map">
<area shape="rect" coords="2,2,268,98" href="mainadmin.php" target="_self">
</map>
<br />
<ul id="css3menu1" class="topmenu">
<li class="topmenu"><a href="index.php" style="width:82px;height:35px;line-height:35px;"><img src="admin_menu2_files/css3menu1/b-home-322.png" alt=""/>Home</a></li>
<li class="topmenu"><a href="mainadmin.php" style="height:35px;line-height:35px;"><span><img src="admin_menu2_files/css3menu1/256base-open-over1.png" alt=""/>Manage Products</span></a>
<ul>
<li class="subfirst"><a href="AddProduct.php"><img src="admin_menu2_files/css3menu1/256sub1.png" alt=""/>Add Products</a></li>
<li><a href="EditProduct.php"><img src="admin_menu2_files/css3menu1/blue-write2.png" alt=""/>Edit Products</a></li>
<li class="sublast"><a href="DeleteProduct.php"><img src="admin_menu2_files/css3menu1/256sub2.png" alt=""/>Delete Products</a></li>
</ul></li>
<li class="topmenu"><a href="order_detail.php" style="width:125px;height:35px;line-height:35px;"><img src="admin_menu2_files/css3menu1/micon2_31.png" alt=""/>Orders Status</a></li>
<li class="topmenu"><a href="Report.php" style="width:92px;height:35px;line-height:35px;"><img src="admin_menu2_files/css3menu1/green-menu-32.png" alt=""/>Reports</a></li>
<li class="topmenu"><a href="edit_profileAdmin.php" style="width:90px;height:35px;line-height:35px;"><span><img src="admin_menu2_files/css3menu1/samples.png" alt=""/>Setting</span></a>
<ul>
<li class="subfirst"><a href="edit_profileAdmin.php"><img src="admin_menu2_files/css3menu1/bservice.png" alt=""/>Edit Profile</a></li>
<li class="sublast"><a href="logout.php"><img src="admin_menu2_files/css3menu1/256base-buy-over.png" alt=""/>Log Out</a></li>
</ul></li>
</ul>
<center><h3>ข้อมูล สินค้า </h3></center>
<table width="943" height="78" border="1" bordercolor="#0066FF">
<tr>
<th width="84" scope="col" bgcolor="#CCFFCC">รหัสสินค้า</th>
<th width="131" scope="col" bgcolor="#CCFFCC">ชื่อสินค้า</th>
<th width="482" scope="col" bgcolor="#CCFFCC">รายละเอียด</th>
<th width="63" scope="col" bgcolor="#CCFFCC">ราคา ฿</th>
<th width="149" scope="col" bgcolor="#CCFFCC">รูปภาพ</th>
</tr>
<?php
include("config.inc.php");
$current_page = 1; //แบ่งเพจ
if(isset($_GET['page'])){
$current_page = $_GET['page'];
}
$row_per_page = 6;
$start_row = ($current_page-1)*$row_per_page;
$sql="select SQL_CALC_FOUND_ROWS * from product order by Pid ASC LIMIT $start_row , $row_per_page;";//เลือกข้อมูลจากฐานข้อมูล
$query = mysql_query($sql) or die (mysql_error());//ฟังก์ชั่นส่งคำสั่งไปที่ my sql
while($rs = mysql_fetch_array($query))
{
$Pid = $rs[0];
$Pname = $rs[1];
$Description = substr($rs[2],0,300)."....";
$Price = $rs[3];
$img = $rs[4];
?>
<tr bgcolor="#FFFFCC">
<td align="center"><?=$Pid;?></td>
<td><?=$Pname;?></td>
<td><?=$Description;?></td>
<td align="right"><?=$Price;?> ฿</td>
<td><? echo"<img src='$img' width=250 height=200>"; ?></td>
<td><ul class='star-rating'>
<li class="current-rating" id="current-rating"><!-- will show current rating --></li>
<span id="ratelinks">
<li><a href="javascript:void(0)" title="1 star out of 5" class="one-star">1</a></li>
<li><a href="javascript:void(0)" title="2 stars out of 5" class="two-stars">2</a></li>
<li><a href="javascript:void(0)" title="3 stars out of 5" class="three-stars">3</a></li>
<li><a href="javascript:void(0)" title="4 stars out of 5" class="four-stars">4</a></li>
<li><a href="javascript:void(0)" title="5 stars out of 5" class="five-stars">5</a></li>
</span>
</ul>
</td>
</tr>
<?
}
if($_GET['do']=='rate'){
// do rate
rate();
}else if($_GET['do']=='getrate'){
// get rating
getRating();
}
// function to retrieve
function getRating(){
$sql= "select * from product";
$result=@mysql_query($sql);
$rs=@mysql_fetch_array($result);
// set width of star
$rating = (@round($rs[value] / $rs[counter],1)) * 20;
echo $rating;
}
// function to insert rating
function rate(){
$text = strip_tags($_GET['rating']);
$update = "update product set counter = counter + 1, value = value + ".$_GET['rating']."";
$result = @mysql_query($update);
if(@mysql_affected_rows() == 0){
$insert = "insert into product (counter,value) values ('1','".$_GET['rating']."')";
$result = @mysql_query($insert);
}
}
?>
</table>
<?
$found_rows = mysql_query("SELECT FOUND_ROWS();"); //แบ่งเพจ
$total_rows = mysql_result($found_rows,0,0);
$total_pages = ceil($total_rows / $row_per_page);
$url = $_SERVER['PHP_SELF'];
if($current_page >1)
{
$pg = $current_page-1;
echo "<a href=\"$url?page=$pg\">Previous</a>";
}
echo " $current_page ";
if($current_page<$total_pages){
$pg =$current_page+1;
echo "<a href=\"$url?page=$pg\">Next</a>";
}
?>
</body>
</html>
Tag : PHP, MySQL, HTML/CSS, JavaScript, jQuery
|
ประวัติการแก้ไข 2013-06-28 18:34:14 2013-06-28 18:34:56 2013-06-28 18:36:04
|
|
|
|
|
Date :
2013-06-28 16:26:28 |
By :
kanokpong |
View :
1464 |
Reply :
3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
หาพวก jQuery UI มาใช้น่ะครับ เยอะแยะ
|
|
|
|
|
Date :
2013-06-28 21:27:54 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
พอจะมีตัวอย่างโค๊ด ไหมครับท่าน
ลองแล้วมันโหวตได้แค่ อันเดี่ยว ที่เหลือ ไม่เกิดอะไรขึ้นครับ พอจะบอกที่แก้ได้ไหมครับ
starrating.js
Code (JavaScript)
// JavaScript Document
$(document).ready(function() {
// get current rating
getRating();
// get rating function
function getRating(){
$.ajax({
type: "GET",
url: "rating/update.php",
data: "do=getrate",
cache: false,
async: false,
success: function(result) {
// apply star rating to element
$("#current-rating").css({ width: "" + result + "%" });
},
error: function(result) {
alert("some error occured, please try again later");
}
});
}
// link handler
$('#ratelinks li a').click(function(){
$.ajax({
type: "GET",
url: "rating/update.php?Pid=$Pid",
data: "rating="+$(this).text()+"&do=rate",
cache: false,
async: false,
success: function(result) {
// remove #ratelinks element to prevent another rate
$("#ratelinks").remove();
// get rating after click
getRating();
},
error: function(result) {
alert("some error occured, please try again later");
}
});
});
});
update.php
Code (PHP)
<?php
// connect to database
$dbh=mysql_connect ("localhost", "root", "1234") or die ('Cannot connect to the database');
mysql_select_db ("jaidog",$dbh);
$Pid = $_GET["$Pid"];
if($_GET['do']=='rate'){
// do rate
rate();
}else if($_GET['do']=='getrate'){
// get rating
getRating();
}
// function to retrieve
function getRating(){
$sql= "select counter,value from product ";
$result=@mysql_query($sql);
$rs=@mysql_fetch_array($result);
// set width of star
$rating = (@round($rs[value] / $rs[counter],1)) * 20;
echo $rating;
}
// function to insert rating
function rate(){
$text = strip_tags($_GET['rating']);
$update = "update product set counter = counter + 1, value = value + ".$_GET['rating']."";
$result = @mysql_query($update);
if(@mysql_affected_rows() == 0){
$insert = "insert into product (counter,value) values ('1','".$_GET['rating']."') ";
$result = @mysql_query($insert);
}
}
?>
|
|
|
|
|
Date :
2013-06-29 01:27:18 |
By :
kanokpong |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Rateit
|
|
|
|
|
Date :
2013-06-29 01:36:40 |
By :
PlaKriM |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|