0 Replies - 297 Views - Last Post: 01 November 2009 - 03:32 AM

#1 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Get random records or users from mysql database

Posted 01 November 2009 - 03:32 AM

Description: these tow snippets will get random records or random users from mysql database
//
$users = mysql_query("SELECT * FROM tblusers")or die(mysql_error());
$rand_user = array();
while($fetch = mysql_fetch_assoc($users)){
        $rand_user[] .=$fetch['Username'];
}
$rand = rand(0,count($rand_user)-1);
echo $rand_user[$rand];


//
$users = mysql_query("SELECT * FROM tblusers ORDER BY Rand() LIMIT 1")or die(mysql_error());
$fetch = mysql_fetch_assoc($users);
echo $fetch['Username'];


Is This A Good Question/Topic? 0
  • +

Page 1 of 1