Gossamer Forum
Home : Products : DBMan SQL : Discussion :

How To: Link to Last/Newst Record

Quote Reply
How To: Link to Last/Newst Record
Hello.

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
support@4cm.com
http://www.4cm.com
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.

Regards,

Eliot Lee
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!