Gossamer Forum
Home : Products : DBMan SQL : Discussion :

randon results

Quote Reply
randon results
Is there a way to show random records?

For example, I would like to show certain records that have a field value set, like "New" or "discount" and show that

Any ideas?

thanks

Fábio
Quote Reply
Re: [assombracao] randon results In reply to
is it possible people?
Quote Reply
Re: [assombracao] randon results In reply to
Hi,

You could do something like below:

$self->{db}->select_options("ORDER BY RAND() LIMIT 0,1");
my $rec = $self->{db}->select({field_name => ['New','Discount']})->fetchrow_hashref;

Cheers,
Jean
Gossamer Threads Inc.

Last edited by:

jean: Feb 26, 2003, 1:58 PM
Quote Reply
Re: [jean] randon results In reply to
Hello Jean

Thanks for your answer, but I need more details

Where do I put that?

thanks

Fábio
Quote Reply
Re: [assombracao] randon results In reply to
In Reply To:
Hello Jean

Thanks for your answer, but I need more details

Where do I put that?

thanks

Fábio
Hello?
Quote Reply
Re: [assombracao] randon results In reply to
Somebody has any solution for that?

where should I put it?
Quote Reply
Re: [assombracao] randon results In reply to
Hi,

Sorry about the late reply!
In this case, you should replace the code below (around line #805 within SQL/Table.pm):

$self->select_options ("ORDER BY $in->{sb} $in->{so}") if ($in->{sb});

WITH:

if ( lc $in->{sb} eq 'rand' ) {
$self->select_options ("ORDER BY rand()");
}
elsif ( $in->{db} ) {
$self->select_options ("ORDER BY $in->{sb} $in->{so}");
}

Hope that helps.

TheStone.
Quote Reply
Re: [TheStone] randon results In reply to
Hello

I tried to put that but I get an error, can You help me?

around the line #805 there is this code

# Set the limit clause, defaults to 25, set to -1 for none.
my $in = $self->_get_search_opts ($opts);
my $offset = ($in->{nh} - 1) * $in->{mh};
$self->select_options ("ORDER BY $in->{sb} $in->{so}") if ($in->{sb});
$self->select_options ("LIMIT $offset, $in->{mh}") unless ($in->{mh} == -1);
Quote Reply
Re: [assombracao] randon results In reply to
Just replace the script with:

# Set the limit clause, defaults to 25, set to -1 for none.
my $in = $self->_get_search_opts ($opts);
my $offset = ($in->{nh} - 1) * $in->{mh};
if ($in->{rand} ) {
$self->select_options ("ORDER BY rand()") ;
}
elsif ($in->{sb}) {
$self->select_options ("ORDER BY $in->{sb} $in->{so}");
}
$self->select_options ("LIMIT $offset, $in->{mh}") unless ($in->{mh} == -1);

TheStone.

B.
Quote Reply
Re: [TheStone] randon results In reply to
Hi

and how can I make it work? what should I pass ? i tried

<input type=hidden name="sb" value="rand">

but did´nt work

Thanks