Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. <?php
  2. // connect to database
  3. $dbh=mysql_connect ("localhost", "root", "") or die ('Cannot connect to the database');
  4. mysql_select_db ("xgn",$dbh);
  5.  
  6. if($_GET['do']=='rate'){
  7.     // do rate
  8.     rate($_GET['id']);
  9. }else if($_GET['do']=='getrate'){
  10.     // get rating
  11.     getRating($_GET['id']);
  12.  
  13. }
  14.  
  15.  
  16. // get data from tabel
  17. function fetchStar(){
  18.     $sql = "select * from `ladder`    ";
  19.     $result=@mysql_query($sql);
  20.     while($rs = @mysql_fetch_array($result,MYSQL_ASSOC)){
  21.         $arr_data[] = $rs;
  22.     }
  23.     return $arr_data;
  24. }
  25.  
  26. // function to retrieve
  27. function getRating($id){
  28.     $sql= "select * from `ladder` where id='".$id."' ";
  29.     $result=@mysql_query($sql);
  30.     $rs=@mysql_fetch_array($result);
  31.     // set width of star
  32.     $rating = (@round($rs[rep_sum] / $rs[rep_count],1)) * 20;
  33.     echo $rating;
  34. }
  35. // function to insert rating
  36. function rate($id){
  37.     $text = strip_tags($_GET['rating']);
  38.     $update = "update `ladder` set rep_count = rep_count + 1, rep_sum = rep_sum + ".$_GET['rating']."  where id='".$id."' ";
  39.     $result = @mysql_query($update);
  40. }
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement