RE: [PHP] Any clever ideas on how to find some random records?
| From: | David Tucker | Date: | Tue, 26 Apr 2005 16:15:21 +0000 |
| Subject: | RE: [PHP] Any clever ideas on how to find some random records? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-213939@lists.php.net to get a copy of this message | ||
[OP]
I have a MySQL database with about a million records. I'd like to use the
SQL command "order by RAND()" but my ISP won't let me: whenever the server
gets spidered, Google overloads their MySQL server because of all the
overhead of that command. I can't just cloak the spiders because I need them
to find the random pages.
So...what I've been doing for small sets of records is to use PHP to
generate a bunch of random record ID's, then I construct a long SQL
statement to find all the matching records. This works, but if I want to
generate a big index page to list a hundred or a thousand records, it could
get pretty clunky.
Anyone have any better suggestions? :)
[/OP]
Well, not knowing what the random records are used for and not really
knowing how random they need to be ;) I might suggest just selecting a
random number and then select all the records after it until you have the
amount you need. Probably not the best solution, but might work for you.
--Codefox