Guest User

Untitled

a guest
Oct 19th, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.52 KB | None | 0 0
  1. function get_random_ids_from_table(&$link, $table, $where = null, $length = -1)
  2. {
  3.     $ids_r = mysqli_query($link, 'select id from `' . $table . '`' . ($where ? ' where ' . $where : '') . ' order by rand()' . ($length && $length > 0 ? ' limit ' . $length : ''));
  4.     if(!$ids_r)
  5.     {
  6.         return array();
  7.     }
  8.    
  9.     $count = mysqli_num_rows($ids_r);
  10.    
  11.     if(!$count)
  12.     {
  13.         return array();
  14.     }
  15.    
  16.     $ids = array();
  17.    
  18.     while($id = mysqli_fetch_assoc($ids_r))
  19.     {
  20.         $ids[] = $id['id'];
  21.     }
  22.     mysqli_free_result($ids_r);
  23.    
  24.     return $ids;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment