Gossamer Forum
Home : Products : DBMan SQL : Discussion :

How To: Link to Last/Newst Record

Quote Reply
How To: Link to Last/Newst Record

wow.... long time since I've been here!

Well, I have my list sort with newest record at the very end. And, I'd like to create a link to that very last/newest record. Or, perhaps the page that contains the last/newest record.

Any suggestions?

As Always, Thanks!

John B. Abela
Quote Reply
Re: How To: Link to Last/Newst Record In reply to
There is a What's New Mod located in the Resource Center for DBMAN that you could adapt for DBMAN SQL.


Eliot Lee
Quote Reply
Here's something I came up with... In reply to

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.

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);
$rows = $sth->fetchrow();

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

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:
Let me know if you use it. I'd like to know if it works for everyone.

Webmaster, TheFew.com
Semper Fi, Do or Die!