RE: [PHP] retrieving random data from mysql database
| From: | Anas Mughal | Date: | Mon, 15 Jul 2002 04:05:30 +0000 |
| Subject: | RE: [PHP] retrieving random data from mysql database | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-107667@lists.php.net to get a copy of this message | ||
When you say,
Order by RAND()
I would think the "Order by" construct expects a column name.
In your case, it gets a decimal value.
How does "Order by" treat decimal values?
Oh, I just checked the manual:
In MySQL Version 3.23, you can, however, do: SELECT * FROM table_name ORDER BY RAND()
I still don't understand how does "Order by" work with a decimal value!!!
David Freeman <dfreeman@outbackqld.net.au> wrote:
> can you teach me how to retrieve random data from my
> database? like for example...i have a list of names on my
> database and i'd like to retrieve only one name at a
> time..randomly. how do i go about this?
This is really a database question rather than a php question and you
haven't said which database you're using so it's hard to give a
definitive answer. In MySQL you'd do something like this:
Select * from some_table where some_condition order by RAND() limit 1;
That would select one random row out of all rows that meet
"some_condition".
CYA, Dave
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
---------------------------------
Do You Yahoo!?
Yahoo! Autos - Get free new car price quotes