Advertisement
pcwizz

Untitled

Sep 5th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. <?php
  2.  
  3. require_once 'config.php';
  4.  
  5. function total_responses(){
  6.     $stmt = $mysqli->prepare("select COUNT(*) from responces");
  7.     $stmt->execute();
  8.     $stmt->bint_result($num_rows);
  9.     $stmt->fetch();
  10.     return $num_rows;
  11. }
  12.  
  13. function responces_for_age($age){
  14.     $stmt = $mysqli->prepare("select COUNT(responces.id) from responces join images on images.id=responces.image_id where age=?");
  15.     $stmt->bind_param("i", $age);
  16.     $stmt->execute();
  17.     $stmt->bind_result($num_rows);
  18.     $stmt->fetch();
  19.     return $num_rows;
  20. }
  21.  
  22. function average_score(){
  23.     $stmt = $mysqli->prepare("select AVG(score) from responces");
  24.     $stmt->execute();
  25.     $stmt->bind_result($avg_score);
  26.     $stmt->fetch();
  27.     return $avg_score;
  28. }
  29.  
  30. function average_score_for_age($age){
  31.     $stmt = $mysqli->prepare("select AVG(score) from responces join images on images.id=responces.image_id where age=?");
  32.     $stmt->bind_param("i", $age);
  33.     $stmt->execute();
  34.     $stmt->bind_result($avg_score);
  35.     $stmt->fetch();
  36.     return $avg_score;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement