Ramdom results?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Perfidus
Forum Contributor
Posts: 114
Joined: Sun Nov 02, 2003 9:54 pm

Ramdom results?

Post by Perfidus »

I have a DB in which one table has info about cities, I would like to query the table in order to choose ramdomly one of the cities and show the info.
Any hints?

Merry Christmas to everyone and peace one day!;)
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

you could use RAND in the query but you need to have..uh..i forgot what version it was implaneted in, try it in ways:

Code: Select all

<?php
$query = query("select city from tablename ORDER BY rand()  LIMIT 5");
?>
if that doest work then get the data into a array and use [php_man]array_rand[/php_man] :) .
Post Reply