Re: random?
| From: | Rob Adams | Date: | Thu, 29 Jan 2004 14:10:45 +0000 |
| Subject: | Re: random? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-176201@lists.php.net to get a copy of this message | ||
"Chris" <chris@glyndower.com> wrote in message
news:NGBBJMAGGLDFGFIBEIJFCEACHIAA.chris@glyndower.com...
> ////////$sql = "SELECT * FROM agentdb WHERE ((OfficeID <> 214) and
> (agentdb.agent_id<> 1115421) and (agentdb.agent_id > 100) and
> agentdb.agent_id <> 333)) ORDER BY RAND() LIMIT 1";
>
> The above code should generate a random agent upon refresh.
>
> It does however seem to favor one agent more than the others. The agent id
>
> it used to favor was "333" i added the "(agentdb.agent_id <> 333)" to
>
> disallow that agent from being displayed. But now it wants to favor an
agent
>
> whose id number is "1167553"
>
> The function can be seen here:
> http://c21alliancerealty.com/area.php it is
>
> the random "Featured Agent" on the left hand side of the page.
>
> Does anyone have any suggestions as to why this is occuring, please?
I don't have any suggestions as to why this happens. Very strange. One
thing you could do instead is depend on PHP's random numbers.
srand ((double) microtime() * 1000000);
$r = mysql_query('select count(*) as cnt from agentb');
$cnt = mysql_result($r, 0, 0);
mysql_free_result($r);
$rnd = rand(1, $cnt);
$sql = "SELECT * FROM agentdb WHERE ((OfficeID <> 214) and
(agentdb.agent_id<> 1115421) and (agentdb.agent_id > 100) and
agentdb.agent_id <> 333)) LIMIT $rnd, 1";
A bit more work than just relying on MySQL, but maybe it will actually be
random...
-- Rob