Jump to content

weird problem - help please?


dmeade

Recommended Posts

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:

 

domainA.com 

               PHP version = 4.2.1

               mySQL version = 3.23.54

               table = 110 records

               Apache Version = 1.3.24 (Unix) 



domainB.com 

               PHP version = 4.2.1

               mySQL version = 3.23.54

               table = 78 records

               Apache Version = 1.3.24 (Unix) 



domainC.com 

               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\',

 PRIMARY KEY  (Quote_ID)

) TYPE=MyISAM;

 

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

}



mysql_free_result($result);

 

 

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,

Dave

Link to comment
Share on other sites

Thanks Hal!

 

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

 

[php:1:981219069a]<?php

$random_seed=rand(1, time());

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

?>[/php:1:981219069a]

 

Thanks again.

- Dave

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.