Share Pastebin
Guest
Public paste!

Såhär?

By: a guest | Mar 18th, 2010 | Syntax: PHP | Size: 0.58 KB | Hits: 90 | Expires: Never
Copy text to clipboard
  1.  84     public static function get_random() {
  2.  85         $sql = 'SELECT `id` FROM `pics` ORDER BY `id` DESC LIMIT 1';
  3.  86         $result = db::out_query($sql);
  4.  87      
  5.  88         $row = $result->fetch_row();
  6.  89         $max_val = $row[0];
  7.  90
  8.  91         $done = 0;
  9.  92        
  10.  93         while ($done == 0) {
  11.  94             $id = rand(1, $max_val);
  12.  95             $sql = 'SELECT * FROM `pics` WHERE `id`='.$id;
  13.  96             $result = db::out_query($sql);
  14.  97             $done = $result->num_rows;
  15.  98         }  
  16.  99
  17. 100         return $result;
  18. 101     }