Jump to content


Photo

Query Help =o


  • Please log in to reply
2 replies to this topic

#1 ssjskipp

ssjskipp
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 06 July 2006 - 09:40 PM

How can I run a query that orders the data randomly?

IE:

Normally, throught PHP and MySQL, I'd do this:

<?
$order = "ORDER BY `id` ASC";
$query = mysql_query("SELECT * FROM `user` WHERE `active` = '1' $order");
$rows = mysql_num_rows($query);
if ($rows > 0){
while($data = mysql_fetch_array($query)){
echo $data["name"];
}
} else {
echo "No users";
}
?>

But how would I do that in a random order, rather than by id and ascending?

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 06 July 2006 - 10:01 PM

...order by rand()
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 ssjskipp

ssjskipp
  • Members
  • PipPip
  • Member
  • 22 posts

Posted 07 July 2006 - 12:12 AM

Thankies ^_^




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users