Gossamer Forum
Home : Products : DBMan : Customization :

Problems with headlines.cgi

Quote Reply
Problems with headlines.cgi
Hi, all.

I use the script below (can't remember where I found it) to display the 5 latest entires in my database. I call it via SSI on a static HTML page. The original script (without the red text) works just fine. I added the red text so that only records with a spesific fieldvalue (Music) should be listed. Problem is that it displays these records ONLY if they are among the 5 latest in TOTAL. I want it to display the 5 latest records that contains this fieldvalue, regardless of other records that may have been added later. Hope you understand, and all help is much welcome!

#!/usr/local/bin/perl
$db_file_name = "/cgi-bin/calendar/default.db"; #### modify the path and filename of your db

open (DB, "<$db_file_name") or &cgierr("error in modify_records. unable to open db file: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
my @lines = <DB>; # Slurp the database into @lines..
close DB;
my $LASTX = 4; # How many headlines do you want?
for ($i=$#lines; $i>=($#lines - $LASTX); $i--) {
chomp $lines[$i];
@data = split(/\|/,$lines[$i]);
$latest .= qq|
<b>$data[7] :</b>

<A HREF="/cgi-bin/calendar/db.cgi?db=default&uid=default&ID=$data[0]&view_records=1" target="_top">$data[1]</A> - $data[2] ($data[4])

| if ($data[5] eq "Music");

#$data[7] is date, $data[0] is record ID, $data[1] is title, $data[2] is description, $data[4] is country and $data[5] is category in my DB

}
print $latest;

1;