Gossamer Forum
Home : Products : DBMan : Customization :

random record

Quote Reply
random record
hi

there is a mod to display a random record. it works fine but the random record is accessible only through a link. i click on a link and then the random record appears.

but i wish to display a random record directly fully displayed in my homepage (a random editorial) through SSI and i cannot do that with the mod mentionned above.

do you have any idea how to display directly a random text or image in my homepage with DbMan ?



Also concerning random records, i wish to display in my homepage a text according to the date. there is a mod too which works fine too. but, if no record is available/specified for one particular day, i wish to display a random text. is there a way to display a random record if the TODAY record is not avalaible (through the 'search failed' sub or however) ?

tanx if you know



cheers



j
Quote Reply
Re: [jigme] random record In reply to
First, have you checked whether your host allows SSI calls, and which type of calls are allowed? You'll need "exec cgi" or "include virtual" for this one.

Then you could call the random record like this:

<!-- # exec cgi="/path/to/dbman/db.cgi?db=database&uid=default&random=on" -->

Then, in sub main in db.cgi, add this:



if ($in{random}) { if ($per_view) { &show_random_record;} else { &html_unauth;}}

Then, in html.pl or db.cgi, add this subroutine:

sub show_random_record {

&html_print_headers; # or whatever you use to print the http header "Content-type: text/html\n\n"

my %rec = &get_random_record;

&html_record(%rec);

}

Now, the actual computation of the random record would need to look like this:

sub get_random_record {

my %rec;

# then there should be some stuff to retrieve a random ID. Let's assume it is then stored in the variable $id

%rec = &get_record($id);

return (%rec);

}

I don't know the random record mod. I hope you can just extract the code that's used to retrieve a random ID for a database record, then you can just paste that code into sub get_random_record, where I have added the line starting with "# then".

I hope this helps,
kellner
Quote Reply
Re: [kellner] random record In reply to
at the end of your codes :

%rec = &get_record($id);



my Key ID is named EditoID

then the code is

%rec = &get_record($EditoID);

or

%rec = &get_record($rec{'EditoID'});

?



anyhow i get as result that the html codes of result appear but the informations of the record don t appear ...



and i get the message 'The database program received a command that it did not understand.' ...

my db works fine as 'include' without 'random=on'



if you know ...



Blush
Quote Reply
Re: [jigme] random record In reply to
The code should be:

%rec = &get_record($rec{'EditoID'});

Please post the complete subroutine, then I can perhaps see what's going wrong.
kellner
Quote Reply
Re: [kellner] random record In reply to
Here are the 2 subroutines added in 'edito_htlm.pl'

sub show_random_record {
# --------------------------------------------------------
# New subroutine : Random record direct display
&html_print_headers; # or whatever you use to print the http header "Content-type: text/html\n\n"
my %rec = &get_random_record;
&html_record(%rec);
}

sub get_random_record {
# --------------------------------------------------------
# New subroutine : Random record direct display
my %rec;
# then there should be some stuff to retrieve a random ID. Let's assume it is then stored in the variable $id
%rec = &get_record($EditoID);
return (%rec);
}



i just changed



elsif ($in{random}) ...


with

elsif ($in{'random'}) ...


in

elsif ($in{'random'}) { if ($per_view) { &show_random_record;} else { &html_unauth;}} # Mod : Random record direct display


but still no result ...

UnimpressedSly
Quote Reply
Re: [jigme] random record In reply to
Well, you forgot to add the code which computes a random number, didn't you? Where does the variable $EditoID get its value from?
kellner
Quote Reply
Re: [kellner] random record In reply to
'the code which computes a random number'

what is it ?



the variable $EditoID is the '$db_key'it is the number of order of each record added as the Record ID.





sorry, i don t know about all that, i just copy and paste ... Crazy

tanx a lot for your help

Laugh
Quote Reply
Re: [kellner] random record In reply to
precision : i use 'relation + friendly' mod
Quote Reply
Re: [jigme] random record In reply to
The variable $EditoID must have a value, like "23", "45". It must get this value from somewhere. So you need code to compute this value, which should be a random number.

The random record mod which you wanted to use originally must contain such code.

So you need to find that code in the random record mod and paste it into the code I have you.
kellner