Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // connect to database
- $dbh=mysql_connect ("localhost", "root", "") or die ('Cannot connect to the database');
- mysql_select_db ("xgn",$dbh);
- if($_GET['do']=='rate'){
- // do rate
- rate($_GET['id']);
- }else if($_GET['do']=='getrate'){
- // get rating
- getRating($_GET['id']);
- }
- // get data from tabel
- function fetchStar(){
- $sql = "select * from `ladder` ";
- $result=@mysql_query($sql);
- while($rs = @mysql_fetch_array($result,MYSQL_ASSOC)){
- $arr_data[] = $rs;
- }
- return $arr_data;
- }
- // function to retrieve
- function getRating($id){
- $sql= "select * from `ladder` where id='".$id."' ";
- $result=@mysql_query($sql);
- $rs=@mysql_fetch_array($result);
- // set width of star
- $rating = (@round($rs[rep_sum] / $rs[rep_count],1)) * 20;
- echo $rating;
- }
- // function to insert rating
- function rate($id){
- $text = strip_tags($_GET['rating']);
- $update = "update `ladder` set rep_count = rep_count + 1, rep_sum = rep_sum + ".$_GET['rating']." where id='".$id."' ";
- $result = @mysql_query($update);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement