Gossamer Forum
Home : Products : DBMan : Installation :

How to indicate the number of Item of a data base ?

Quote Reply
How to indicate the number of Item of a data base ?
Thanks for your response, but in fact I want to put the number of Item
in My database.
For exemple if you go into my Games Solutions Data Base, I want to
indicate to the visitor the number of games solutions I have in by
database.

Thank you in advance
Best Regards

------------------
------------------------
mailto:greg@hermel.com
http://www.hermel.com
Quote Reply
Re: How to indicate the number of Item of a data base ? In reply to
If you want to show on the home page how many records you have in your database, the following should work:

In html.pl, sub html_home

before

&html_print_headers;

add

$in{$db_key} = "*";
query();


Then, wherever you want the number of records to show up, use something like

There are $db_total_hits records in the database.

Or whatever wording you want to use.

BTW, this is untested, but it won't hurt anything if it isn't right. Seems like it would work, though.

Hope this helps.



------------------
JPD
Quote Reply
Re: How to indicate the number of Item of a data base ? In reply to
Probably a more efficent way:

open(FILE, "< $db_file_name") or &cgierr("can't open $db_file_name: $!");
$count++ while <FILE>;
close FILE;

and $count will have your count in it. This skips a lot of unecessary work done by &query.

Cheers,

Alex
Quote Reply
Re: How to indicate the number of Item of a data base ? In reply to
Brilliant ! I added this one too. Is there a similar way to show when the database was last updated ? I do have a field ADDED in the database. So if there's a quick way to retrieve the max date...
Quote Reply
Re: How to indicate the number of Item of a data base ? In reply to
I suppose you could do a "List All," sorting by "ADDED," descending. That would put the latest addition at the top. If you have a large number of records in your db, though, it would take a while.

Maybe folks who know more about Perl than I do would have a better answer, though.

------------------
JPD
Quote Reply
Re: How to indicate the number of Item of a data base ? In reply to
Or you could do:

$date = (stat($db_file_name))[9];
($day, $month, $year) = (localtime($date))[3,4,5,];
$month++; $year = $year + 1900;
print "Last Updated: $year-$month-$day";

Hope that helps,

Alex