<?php
/* you have to get owner and visitor of the profile */
$owner_id=$_REQUEST['owner_id'];
$visitor_id=$_REQUEST['visitor_id'];
$status=$_REQUEST['status'];
$qry=mysql_query("select * from rateProfile where where owner_id=\"$owner_id\" ");
if(mysql_num_rows($qry)>0){
$getrate=mysql_fetch_object($qry);
$cum_rate=$getrate->cum_rate;
$total=$getrate->total;
$val=floor($cum_rate/$total);
}else{
$val=0;
}
if($val==0){
$img='Take the first chance to rate this profile!!!';
}elseif ($val==1){
$img="<img src=\"images/stars1.gif\">";
}elseif ($val==2 ) {
$img= "<img src=\"images/stars2.gif\">";
} elseif ( $val==3){
$img= "<img src=\"images/stars3.gif\">";
}elseif ( $val==4){
$img= "<img src=\"images/stars4.gif\">";
}elseif ( $val==5){
$img= "<img src=\"images/stars5.gif\">";
}
?>
<html>
<head><title>Simple profile rating</title></head>
<body>
<?php
if(isset($_REQUEST['$status']))
{
if($status==1) { ?>
<?php
} elseif($status==2){ ?>
<table align="center" width="550">
<tr><td align=\"center\" colspan=\"2\">You have already rated this profile</td></tr></table>
<?php }
elseif($status==2){ ?>
<table align="center" width="550">
<tr><td align=\"center\" colspan=\"2\">select a rate!! </td></tr></table>
<?php }
}
if($owner_id!=$visitor_id){
?>
<form name='frmRating' action='rateAction.php' method='post'>
<p> Rating: <?php echo $img;?></p>
<p><h1>Rate this profile</h1>
<select name="rates" id='rates'>
<option value="0" selected>Select rating
<option value="1">*
<option value="2">**
<option value="3">***
<option value="4">****
<option value="5">*****
</select>
</p>
<p> The star has the following meaning
<table border=0 cellpadding=3 >
<tr><td align=right>*</td><td>bad</td></tr>
<tr><td align=right>**</td><td>mediocre</td></tr>
<tr><td align=right>***</td><td>good</td></tr>
<tr><td align=right>****</td><td>very good</td></tr>
<tr><td align=right>*****</td><td>excellent</td></tr>
</table> </p>
<p>
<input type='hidden' name='owner_id' value='<?php echo $owner_id;?>'>
<input type='hidden' name='visitor_id' value='<?php echo $visitor_id;?>'>
</p>
<p>
<input type='submit' value='rate!'>
</p>
</form>
<?php } ?>
</body>
</html>
rateAction.php
<?php
/* tables used :2
rateProfile :id(auto_increment,int),
owner_id(int),
cum_rate(int),
total(int): total count of ratings to the profile
rateProfile_history : for storing rating history
id(auto_increment,int),
owner_id(int),
rater_id(int),
rate(int): ratings by the visitor
*/
$conn=mysql_connect("localhost","root","root");
$db=mysql_select_db("dbCommunity");
$owner_id=$_REQUEST['owner_id'];
$visitor_id=$_REQUEST['visitor_id'];
$rate=$_REQUEST['rates'];
if($rate>0){
/* to check whether the visitor has already rated the profile or not */
$qry=mysql_query("select * from rateProfile_history where rater_id='$visitor_id' and owner_id='$owner_id'");
$obj=mysql_fetch_object($qry);
$num=mysql_num_rows($qry);
/* if rated redirect to already rated page*/
if($num==1){
header("location:ratehome.php?owner_id=$owner_id&visitor_id=$visitor_id&status=2");
}else{
($qryt=mysql_query("Select * from rateProfile where where owner_id=\"$owner_id\" ");
} }
}else{ header("location:ratehome.php?owner_id=$owner_id&visitor_id=$visitor_id&status=3"); }
?>
0 comments
Post a Comment
Please put your comments here. your questions, your suggestions, also what went wrong with me.