Gossamer Forum
Home : Products : DBMan : Customization :

Random links

Quote Reply
Random links
Hi,

This must have been used before,
How random display a set number of DBman links on say a home page each time it is loaded.
possibly using ssi.

Cheers for any help

Norvin
Quote Reply
Re: [Syte] Random links In reply to
The SSI would be up to someone else, but I'm not sure what you mean by "DBman links."


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Random links In reply to
Sorry if I did not make it clear.
I was wantinmg to display 5 random records on a home page that would be taken from my DBman database.

Any ideas

Cheers
Quote Reply
Re: [Syte] Random links In reply to
Okay. Random record.

The best thing I can suggest is that you do a search of this forum for the word random. There is a lot of stuff there, with a lot of different possibilities. See if you can find something that already exists that will suit your needs. We might need to polish it a bit, but there's no use starting from scratch if it's not necessary.


JPD
----------------------------------------------------
JPDeni's DBMan-ual
How to ask questions the smart way.
Quote Reply
Re: [JPDeni] Random links In reply to
Check out this post:
http://www.gossamer-threads.com/perl/gforum/gforum.cgi?post=189253

It references how to pull in records using SSI

the biggest problem will be the "ID=*"

If you wanted to pull in five specific records you could cut & paste the SSI code five times and replace the ID=001 with ID=002, etc. Your biggest problem here would be some way to rewrite the ID numbers each time the page is loaded (on the index.shtml page). OR you could have some way to denote 5 "random" records in your db - perhaps a special field for random? (ie, random = "yes") But this would only update every so often (when the script is ran, or an Admin initiated it) and not each time the home page loaded.

Maybe a combination of JavaScript and SSI (or just JavaScript) ?

Hmm...
Quote Reply
Re: [Watts] Random links In reply to
Check out the FAQ (maintained by LoisC) at:

http://redundantcartridge.com/dbman/

Look under SSI - there are mods for pulling random records, etc.

I think that will suite your needs.
Quote Reply
Re: [Watts] Random links In reply to
Cheers all for that, yes it is the "ID=*" that is the problem mainly due to IF there is a record at that number when it is called, (As records are added and delete from the database).
I will look again at what has been done then work something out.

Cheers
Quote Reply
Re: [Syte] Random links In reply to
Hi again,
I have put this together and call via SSI
However substituting &get_record($random_record_id) for a Number of a record in the database works fine otherwise I cant get it to show the existing records.
Anyone have some idea as to what may be wrong here.
I am call the cgi
cgi-bin/stock/db.cgi?db=default&uid=default&random=on
Cheers

sub show_random_record {

&html_print_headers;
"Content-type: text/html\n\n"

my %rec = &get_random_record;
print $random_num;
&html_record(%rec);

}

sub get_random_record {

my %rec;

# Get a RND number from the existing records in the database
srand();
my (@id_numbers) = ();
open(FILE, "<$db_file_name") or &cgierr ("Error loading required libraries.\nCheck that they exist, permissions are set correctly and that they compile.\nReason: The database file could not be opened for reading in sub html_footer for looking up the random record!");
while (<FILE>) {
my($line) = $_;
chomp($line);
my(@fields) = split(/$db_delim/, $line);
push (@id_numbers, int($fields[$id_field_position]));
}
close(FILE);
$random_num = int(rand($#id_numbers + 1));
$random_record_id = $id_numbers[$random_num];


%rec = &get_record($random_record_id);

return (%rec);

}
Quote Reply
Re: [Syte] Random links In reply to
I would try for a start changing:

sub show_random_record {

&html_print_headers;
"Content-type: text/html\n\n"

to:

sub show_random_record {

print "Content-type: text/html\n\n";

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/
Quote Reply
Re: [LoisC] Random links In reply to
Cheers All for the help.

I have cracked it, a little mod that will show any part of a record in any formatted layout, from the exisiting records in the database, in random order by SSI on a static page.

If anyone is interested in this mod as i could not find one to do this in the forum, I will be happy to post it here.

Thanks again for everyones help

Norvin
Quote Reply
Re: [Syte] Random links In reply to
Yes, please post your solution so that others who are needing that function can benefit from what you created.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/