Re: Random PostreSQL
| From: | Matrix | Date: | Wed, 02 Aug 2000 18:46:35 +0000 |
| Subject: | Re: Random PostreSQL | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-9706@lists.php.net to get a copy of this message | ||
I had a similar problem, though I worked around it.
in my script it grabs 4 random images from the postgress database and each
time a random number is picked it checks it agains any other numbers that
have picked to stop double images from showing.
$result = pg_exec($db, "SELECT * FROM db ORDER BY id;");
$numrows = pg_numrows($result) - 1;
srand((double)microtime()*100000);
$ran1 = rand(0,$numrows);
$ran2 = rand(0,$numrows);
while($ran2 == $ran1){
$ran2 = rand(1,$numrows);
}
$ran3 = rand(1,$numrows);
while($ran3 == $ran1 || $ran3 == $ran2){
$ran3 = rand(0,$numrows);
}
$ran4 = rand(0,$numrows);
while($ran4 == $ran1 || $ran4 == $ran2 || $ran4 == $ran3){
$ran4 = rand(1,$numrows);
}
$border ="border=0";
$img1 = pg_result($result, $ran1, "img_name");
$path1 = pg_result($result, $ran1, "path");
$url1 = pg_result($result, $ran1, "url");
$alt1 = pg_result($result, $ran1, "business");
Mike Sears
http://via2k.vianet.ca
Web Developer
----- Original Message -----
From: <joe@jWebMedia.com>
To: <php-general@lists.php.net>
Sent: Tuesday, August 01, 2000 1:26 PM
Subject: [PHP] Random PostreSQL
> Anyone know of a simple way to select a random group of records from
> postgeSQL? Can't find anything in the manual that is of any help to me.
> Thanks,
>
> Joe
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>