Jump to content


weird problem - help please?

  • Please log in to reply
2 replies to this topic

#1 dmeade

  • New Members
  • Pip
  • Newbie
  • 3 posts
  • LocationChicago

Posted 18 February 2003 - 11:18 PM

I have a bizarre problem and would greatly appreciate any help.

I am administering several web sites. On each I have installed the same mySQL databases and PHP code, on servers which are similarly configured. However the code is behaving differently on each domain.

I\'m trying to use \"ORDER BY RAND() limit 1\" to retrieve a random record. On \"Domain A\" this is working flawlessly. On \"Domain B\" it appears to work once and a (very great) while -- but almost never. And, on \"Domain C\" this rarely works at all.

Each domain has the following set up:


                PHP version = 4.2.1

                mySQL version = 3.23.54

                table = 110 records

                Apache Version = 1.3.24 (Unix) 



                PHP version = 4.2.1

                mySQL version = 3.23.54

                table = 78 records

                Apache Version = 1.3.24 (Unix) 


                PHP version = 4.2.1

                mySQL version = 3.23.54

                table = 45 record

                Apache Version = 1.3.26 (Unix)

And each domain has the following table definition:

CREATE TABLE Quote_Board (

  Quote_ID int(11) NOT NULL auto_increment,

  Quote text NOT NULL,

  Person text NOT NULL,

  URL text,

  Type set(\'Spoken\',\'IM\',\'Email\',\'Other\') default \'Spoken\',

  Submitted_by text,

  Quote_Date date default NULL,

  Submission_Date date default NULL,

  approved enum(\'Y\',\'N\') NOT NULL default \'N\',



And each domain is using the following PHP code:

$query = "SELECT * FROM `Quote_Board` WHERE approved = \'Y\' ORDER BY RAND() limit 1";

$result = mysql_query($query) or die("Query failed");

while ($quote = mysql_fetch_array($result, MYSQL_BOTH)) {

  // print resutls in HTML



I just can\'t figure out why it is working so well on one domain and so poorly on the other.

Thanks in advance for any help,

#2 hal9000

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 23 February 2003 - 06:20 PM


#3 dmeade

  • New Members
  • Pip
  • Newbie
  • 3 posts
  • LocationChicago

Posted 23 February 2003 - 08:55 PM

Thanks Hal!

Combining several of the ideas from that thread I managed to come up with a good solution:

$random_seed=rand(1, time());
$query = \"SELECT * FROM $table ORDER BY RAND($random_seed) limit 1\";

Thanks again.
- Dave

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users