|
|
|
รบกวนดูโค๊ดให้หน่อยค่า คือเรากดให้มันโหวตแล้วมันจะโหวตให้ทุกตัว แต่ถ้ากำหนด ID เข้าไปมันจะโหวตแต่ตัวแรกค่ะ |
|
|
|
|
|
|
|
รบกวนช่วยดูให้หน่อยนะค่ะ งงมากเลยค่ะ ขอบคุณมากค่ะ
ProjectDetail.php
Code (PHP)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<script href="bootstrap/js/bootstrap.min.js" rel="stylesheet"></script>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-1.7.min.js" ></script>
<link rel="stylesheet" type="text/css" href="bootstrap/css/style.css" />
<link rel="icon" href="http://vandelaydesign.com/favicon.ico">
<link href="bootstrap/font-awesome/css/font-awesome.min.css" rel="stylesheet">
<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>
<div class="container">
<div class="header">
<!-- head sit -->
<table width="1181">
<tr>
<td width="314" rowspan="3">
<center><img src="bootstrap/Picture/logo.png"/img></center></td>
<td colspan="2">
<center><img src="bootstrap/Picture/head1.png"/img></center></td>
</tr>
<!-- login info -->
<tr>
<td width="751"><div align="right">Welcome, admin</div></td>
<td width="100">
<div align="right"><button type="submit" class="btn" name="submit" value="Submit"/>Logout</div>
</td>
</tr>
<!-- icon -->
<tr>
<td width="751">
<div align="right">
<img height="23" width="23" src="Icon/UploadProj.png">Upload Project</img>
<img height="23" width="23" src="Icon/Register.png"></img>
<a href="Registeration.php" style="text-decoration:none" >Register</a>
<img height="23" width="23" src="Icon/Member.png"> Member</img>
</div>
</td>
<td width="100"></td>
</tr>
</table>
</div>
<div class="clear"></div>
<!-- left container -->
<div class="left-container">
<td width="402"><img src="bootstrap/Picture/TRanking.png"></img></td>
</div>
<!-- right container -->
<div class="right-container">
<img src="bootstrap/Picture/TProjList.png"></img>
<br/>
<?
//session_start();
include("Connection.php");
$id = $_GET['id'];
$strSQL = "SELECT * FROM ProjectInfo WHERE ID = '".$id."'";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
$path = "myfile/";
while($objResult = mysql_fetch_array($objQuery))
{
$image = $objResult['ProjectPic'];
?>
<h4><div align="center" class="projlist"><?=$objResult["ProjectName"];?> ----------------------------------------------------</div></h4>
<br/><br/>
<center><img src="myfile/<?=$objResult["ProjectPic"];?>" class="img-polaroid"></img></center>
<br/><br/>
<table>
<tr><td>Project ID:</td><td><?=$objResult["ID"];?></td></tr>
<tr><td>Project Name:</td><td><?=$objResult["ProjectName"];?></td></tr>
<tr><td>Programming Language:</td><td><?=$objResult["Language"];?></td></tr>
<tr><td>Advisor:</td><td><?=$objResult["Advisor"];?></td></tr>
<tr><td>Project Type:</td><td><?=$objResult["ProjectType"];?></td></tr>
<tr><td>Course Name:</td><td><?=$objResult["CourseName"];?></td></tr>
<tr><td>Year:</td><td><?=$objResult["CourseName"];?></td></tr>
<tr><td>Why is it CS Showcase?:</td><td><?=$objResult["Question"];?></td></tr>
<tr><td>Reward:</td><td><?=$objResult["Reward"];?></td></tr>
</table>
<center><a href="myfile/<?=$objResult["ProjectFile"];?>" class="btn"><i class="icon-cloud-download"></i> Download</a></center>
<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>
<?
}
mysql_close();
?>
</div>
<div class="down-container">
<form method="post">
<center><textarea name="comment" style="width:500px" rows="5"></textarea></center>
<center><button class="btn" type="submit"><i class="icon-comment"></i> Comment</button></center>
<form>
</div>
</div>
<style type="text/css">
body {
background-image:url(bootstrap/Picture/Bg.png);
}
</style>
update.php
Code (PHP)
<?php
// connect to database
$dbh=mysql_connect ("localhost", "root", "123") or die ('Cannot connect to the database');
mysql_select_db ("csv",$dbh);
if($_GET['do']=='rate'){
// do rate
rate();
}else if($_GET['do']=='getrate'){
// get rating
getRating();
}
// function to retrieve
function getRating(){
$sql= "select * from ProjectInfo";
$result=@mysql_query($sql);
$rs=@mysql_fetch_array($result);
// set width of star
$rating = (@round($rs[Vote] / $rs[Counter_vote],1)) * 20;
echo $rating;
}
// function to insert rating
function rate(){
$text = strip_tags($_GET['rating']);
$update = "update ProjectInfo set Counter_vote = Counter_vote + 1, Vote = Vote + ".$_GET['rating']."";
$result = @mysql_query($update);
if(@mysql_affected_rows() == 0){
$insert = "insert into ProjectInfo (Counter_vote,Vote) values ('1','".$_GET['rating']."')";
$result = @mysql_query($insert);
}
}
?>
staring.js
Code (PHP)
// JavaScript Document
$(document).ready(function() {
// get current rating
getRating();
// get rating function
function getRating(){
$.ajax({
type: "GET",
url: "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: "update.php",
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");
}
});
});
});
Tag : PHP
|
|
|
|
|
|
Date :
2013-07-12 14:34:00 |
By :
mrronalz |
View :
683 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองเปลี่ยนรูปแบบคำถามใหม่ครับ
|
|
|
|
|
Date :
2013-07-15 09:07:04 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|