Gossamer Forum
Home : Products : DBMan SQL : Discussion :

Here's something I came up with...

Quote Reply
Here's something I came up with... In reply to
John,

I run a Marine Guestbook and I'm using DBMan SQL. I wanted to do something similar to what you want, except I only want the latest entry to show up on the main menu (Our Latest Marine to sign the guestbook was: NAME HERE WITH LINK TO RECORD). Here's what I came up with to do the job. It's short and simple and works great! My $db_key is an incremental ID# so I think this made it a little easier to do.

Code:
in db.cgi
ADD NEW Subroutine:

sub last_entry {
# --------------
my ($sth, $rows, $query, $rank, $fname, $lname, $served, $entry, @data);

$query = "SELECT $db_key FROM $db_table ORDER BY $db_key DESC LIMIT 1";
$sth = $DBH->prepare($query);
$sth->execute();
$rows = $sth->fetchrow();

$query = "SELECT Rank,First,Last,Served FROM $db_table WHERE $db_key = $rows";
$sth = $DBH->prepare($query);
$sth->execute();

while (@data = $sth->fetchrow_array) {
$rank = $data[0];
$fname = $data[1];
$lname = $data[2];
$served = $data[3];
}
$entry = qq|<a href="$db_script_link_url&ID=$rows&view_records=1">$rank $fname $lname ($served)</a>|;
return $entry;
}


in html.pl
in sub html_home

Add this wherever you want to show the record with the link:
| . &last_entry . qq|

For example:
print qq|The last Marine to register their name was:<BR><center>| . &last_entry . qq|.</center><BR>|;
That's it. Of course you need to edit the sub last_entry for what and how you want it to show up. You can see it in action at:
http://www.thefew.com/...bin/guestbook/db.cgi
Let me know if you use it. I'd like to know if it works for everyone.


AJ
Webmaster, TheFew.com
http://www.thefew.com
Semper Fi, Do or Die!
Subject Author Views Date
Thread How To: Link to Last/Newst Record Yokhannan 3725 Jul 2, 2000, 7:15 AM
Post Re: How To: Link to Last/Newst Record
Stealth 3600 Jul 2, 2000, 12:03 PM
Post Here's something I came up with...
TheFew 3590 Jul 3, 2000, 10:47 AM