Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get_random_ids_from_table(&$link, $table, $where = null, $length = -1)
- {
- $ids_r = mysqli_query($link, 'select id from `' . $table . '`' . ($where ? ' where ' . $where : '') . ' order by rand()' . ($length && $length > 0 ? ' limit ' . $length : ''));
- if(!$ids_r)
- {
- return array();
- }
- $count = mysqli_num_rows($ids_r);
- if(!$count)
- {
- return array();
- }
- $ids = array();
- while($id = mysqli_fetch_assoc($ids_r))
- {
- $ids[] = $id['id'];
- }
- mysqli_free_result($ids_r);
- return $ids;
- }
Advertisement
Add Comment
Please, Sign In to add comment