Advertisement
pcwizz

Untitled

Sep 5th, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.61 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. }
  38.  
  39. function average_score_in_time_period($time_start, $time_end){
  40.     $stmt = $mysqli-prepare("select AVG(score) from responces where datetime >= ? or datetime <= ?");
  41.     $stmt->bind_param("ii", $time_start, $time_end);
  42.     $stmt->execute();
  43.     $stmt->bind_param($avg_score);
  44.     return $avg_score;
  45. }
  46.  
  47. function average_score_for_age_in_time_period($age, $time_start, $time_end){
  48.     $stmt = $mysqli-prepare("select AVG(score) from responces join images on images.id=responces.image_id where age=? and (datetime >= ? or datetime <= ?)");
  49.     $stmt->bind_param("ii", $time_start, $time_end);
  50.     $stmt->execute();
  51.     $stmt->bind_param($avg_score);
  52.     return $avg_score;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement