RE: [PHP] retrieving random data from mysql database
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!!! I don't pretend to have all the answer. I just know that I had reason to work this one out for myself a while back and when I consulted the MySQL manual it gave sample code on what to do in MySQL to achieve this result. I accepted that fact and used it. I haven't needed any deeper information on this one so I haven't looked. I suspect if you really want to know how it works then you'll have to ask this question again on a MySQL-specific list - and perhaps even a MySQL developers list. CYA, Dave -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] retrieving random data from mysql database
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
Re: [PHP] retrieving random data from mysql database
SELECT RANDOM name FROM table or SELECT name FROM table ORDER BY RANDOM LIMIT 1 not tested, used at your own free will. -- me - Original Message - From: mm fernandez [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Sunday, July 14, 2002 11:37 PM Subject: [PHP] retrieving random data from mysql database hi, 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? hope someone can help...thanx. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] retrieving random data from mysql database
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 [EMAIL PROTECTED] 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