Advertisement
pcwizz

Untitled

Sep 5th, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.59 KB | None | 0 0
  1. <?php
  2.  
  3. header("content-type: application/javascript");
  4.  
  5. require_once 'config.php';
  6.  
  7. function number_of_images(){
  8.     $stmt = $mysqli->prepare("select COUNT(*) from images");
  9.     $stmt->execute();
  10.     $stmt->bind_result($num_rows);
  11.     $stmt->fetch():
  12.     return $num_rows;
  13. }
  14.  
  15. function image_uri($id){
  16.     $stmt = $mysqli->prepare("select uri from images where id=?");
  17.     $stmt->bind_param("i", $id);
  18.     $stmt->execute();
  19.     $stmt->bind_result($uri);
  20.     return uri;
  21. }
  22.  
  23. $image_id = rand(0, number_of_images());
  24. $image_uri = image_uri($image_id);
  25.  
  26. echo "{\"image_id\":$image_id, \"image_uri\":\"$image_uri\"}";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement