Обсуждение: FW: Random Selection from TABLE

Поиск
Список
Период
Сортировка

FW: Random Selection from TABLE

От
"Kris-Jon Fenton"
Дата:
Hi,

I have a table that simply holds three fields:
    serial_id
    image_name
    image_text

I want to be able to select entries randomly so I can change the images on a
website using PHP.

Basically I need to have a randomly rotating image that will change whenever
the page is refreshed.

I want to store the image names in a table and have them selected from
there.

Using PostgreSQL version 7.1.3-2

Thanks
Kris


Re: FW: Random Selection from TABLE

От
"Josh Berkus"
Дата:
Kris,

> I want to be able to select entries randomly so I can change the
> images on a
> website using PHP.
>
> Basically I need to have a randomly rotating image that will change
> whenever
> the page is refreshed.
>
> I want to store the image names in a table and have them selected
> from
> there.

Sounds like fun!  Do you have a question for the list?

-Josh

______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco

Re: FW: Random Selection from TABLE

От
"Kris-Jon Fenton"
Дата:
Yes, I do have a question, how do I do this?

-----Original Message-----
From: pgsql-novice-owner@postgresql.org
[mailto:pgsql-novice-owner@postgresql.org]On Behalf Of Josh Berkus
Sent: Friday, 21 December 2001 2:41 AM
To: Kris-Jon Fenton; pgsql-novice@postgresql.org
Subject: Re: [NOVICE] FW: Random Selection from TABLE


Kris,

> I want to be able to select entries randomly so I can change the
> images on a
> website using PHP.
>
> Basically I need to have a randomly rotating image that will change
> whenever
> the page is refreshed.
>
> I want to store the image names in a table and have them selected
> from
> there.

Sounds like fun!  Do you have a question for the list?

-Josh

______AGLIO DATABASE SOLUTIONS___________________________
                                       Josh Berkus
  Complete information technology      josh@agliodbs.com
   and data management solutions       (415) 565-7293
  for law firms, small businesses        fax 621-2533
    and non-profit organizations.      San Francisco

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)


Re: FW: Random Selection from TABLE

От
Salvatore Sferrazza
Дата:
I've implemented something like this before, the way we solved it was by
having a list of "candidate" images in a table indexed by some entity.  We
then used the front end tool (in our case, Java) to select the candidates,
cache them and then pull randomly from the cache upon rendering the
page.  Asking SQL to do this may not be the best idea, since you don't
want one more round-trip per page.

HTH,

Sal

On Fri, 21 Dec 2001, Kris-Jon Fenton wrote:

> Yes, I do have a question, how do I do this?
>
> -----Original Message-----
> From: pgsql-novice-owner@postgresql.org
> [mailto:pgsql-novice-owner@postgresql.org]On Behalf Of Josh Berkus
> Sent: Friday, 21 December 2001 2:41 AM
> To: Kris-Jon Fenton; pgsql-novice@postgresql.org
> Subject: Re: [NOVICE] FW: Random Selection from TABLE
>
>
> Kris,
>
> > I want to be able to select entries randomly so I can change the
> > images on a
> > website using PHP.
> >
> > Basically I need to have a randomly rotating image that will change
> > whenever
> > the page is refreshed.
> >
> > I want to store the image names in a table and have them selected
> > from
> > there.
>
> Sounds like fun!  Do you have a question for the list?
>
> -Josh
>
> ______AGLIO DATABASE SOLUTIONS___________________________
>                                        Josh Berkus
>   Complete information technology      josh@agliodbs.com
>    and data management solutions       (415) 565-7293
>   for law firms, small businesses        fax 621-2533
>     and non-profit organizations.      San Francisco
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>


Re: FW: Random Selection from TABLE

От
Philip Hallstrom
Дата:
I don't know how efficient it would be, but you could always do:

select * from mytable order by random() limit 1;

-philip

On Thu, 20 Dec 2001, Salvatore Sferrazza wrote:

> I've implemented something like this before, the way we solved it was by
> having a list of "candidate" images in a table indexed by some entity.  We
> then used the front end tool (in our case, Java) to select the candidates,
> cache them and then pull randomly from the cache upon rendering the
> page.  Asking SQL to do this may not be the best idea, since you don't
> want one more round-trip per page.
>
> HTH,
>
> Sal
>
> On Fri, 21 Dec 2001, Kris-Jon Fenton wrote:
>
> > Yes, I do have a question, how do I do this?
> >
> > -----Original Message-----
> > From: pgsql-novice-owner@postgresql.org
> > [mailto:pgsql-novice-owner@postgresql.org]On Behalf Of Josh Berkus
> > Sent: Friday, 21 December 2001 2:41 AM
> > To: Kris-Jon Fenton; pgsql-novice@postgresql.org
> > Subject: Re:  FW: Random Selection from TABLE
> >
> >
> > Kris,
> >
> > > I want to be able to select entries randomly so I can change the
> > > images on a
> > > website using PHP.
> > >
> > > Basically I need to have a randomly rotating image that will change
> > > whenever
> > > the page is refreshed.
> > >
> > > I want to store the image names in a table and have them selected
> > > from
> > > there.
> >
> > Sounds like fun!  Do you have a question for the list?
> >
> > -Josh
> >
> > ______AGLIO DATABASE SOLUTIONS___________________________
> >                                        Josh Berkus
> >   Complete information technology      josh@agliodbs.com
> >    and data management solutions       (415) 565-7293
> >   for law firms, small businesses        fax 621-2533
> >     and non-profit organizations.      San Francisco
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 2: you can get off all lists at once with the unregister command
> >     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 6: Have you searched our list archives?
> >
> > http://archives.postgresql.org
> >
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>