×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: SQL
Posted by: bejoy balan
Added: Oct 2, 2014 11:10 AM
Views: 16
Tags: mysql random
Random row from mysql table
  1. $offset = $db->query("SELECT FLOOR(RAND() * COUNT(*)) AS `offset` FROM `{$table}` ")->fetch();
  2. $result = $db->query("SELECT * FROM `{$table}` LIMIT {$offset['offset']}, 1 ");
  3.  
  4.  
  5.  
  6. SELECT FLOOR(RAND() * COUNT(*)) AS `offset`, COUNT(*) FROM blends_components;
  7.