Gossamer Forum
Home : Products : DBMan : Customization :

Total records

Quote Reply
Total records
Is there a variabel in dbman which can display the total number of records, like $grand_total in links ??

Michael
Quote Reply
Re: Total records In reply to
You can use the following sub-routine in the db.cgi file:

Code:
sub num_records {
# --------------------------------------------------------
# Displays the number of records

my $count = 0;
open (DB, "<$db_file_name") or &cgierr("error in num_records. unable to open dat
abase:$db_file_name.\nReason: $!");

LINE: while (<DB> ) {
if (!(/^#/) && !(/^\s*$/)) {
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
}
++$count;
}
close DB;
print $count;
}

Then in your html.pl file, add the following codes to show the total number of records:

Code:
|; &num_records; print qq|

Hope this helps.

[Edited for the third time due to dumb errors on the part of the coder]

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------




[This message has been edited by Eliot (edited November 24, 1999).]

[This message has been edited by Eliot (edited December 18, 1999).]

[This message has been edited by Eliot (edited December 20, 1999).]
Quote Reply
Re: Total records In reply to
Maybe easier:
Code:
open (DB, "<$db_file_name") or &cgierr("error in search. unable to open database: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;
$items = scalar(@lines);
print qq|There are $items items in the database.|;
Quote Reply
Re: Total records In reply to
Eliot, I get server error using your script.
Maybee I made something wrong
_________________________________

So I tried martīs idea. It works

Thank you both!!
_________________________________
I inserted martīs script in the header combined with a fast search. Iīm very satisfied.

Michael
Quote Reply
Re: Total records In reply to
Well, I may have made one or two syntax errors. I copied the version I have in my db.cgi file and I noticed that I had two if statements that probably did not pertain to your DBMAN, so I erased them before I went to lunch and neglected to come back to the forum to further edit the codes.

Sorry.

Goodbye.

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: Total records In reply to
Eliot,

I tried your hack, but it gives me a result of 0. I also tried mart's hack, but the result it gave was too high. I think it's because some of the lines in my database are wrapped, and mart's code counts the wrapped part of the line as another record.

Would wrapped lines have this effect? Also, can you think of why I might be getting a result of 0? I copied the code like you have it here.
Quote Reply
Re: Total records In reply to
Wrapping lines does not affect the script.

I don't know why the MOD I posted does not work.

Regards.

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: Total records In reply to
Eliot, now you're missing the closing bracket on the if loop... put it before the ++$count; line. Wink

[This message has been edited by oldmoney (edited December 18, 1999).]
Quote Reply
Re: Total records In reply to
Thanks for holding my hand, oldmoney. I did forget the closing right bracket for the loop.

Regards.

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: Total records In reply to
Hey, Eliot, you're ten times the coder I am. In regards to my own meager abilities, I am fond of the expression "even a blind squirel finds a nut once in a while."

[This message has been edited by oldmoney (edited December 19, 1999).]
Quote Reply
Re: Total records In reply to
" Then in your html.pl file, add the following codes to show the total number of records:
code:

|; num_records; print qq|
------------------------------
This code gives me only errors in the html.pl file.
Should it be : print qq|num_records; |;
?
or am I missing the point here?

Thanx
Catch


------------------
Quote Reply
Re: Total records In reply to
catch,

You almost got it....Yet the codes should be as follows:

Code:
|; &num_records; print qq|

I inadvertantly forget the & character to call that sub-routine.

I will edit my previous post...again.

Wink

Regards,

------------------
Eliot Lee
Anthro TECH,L.L.C
www.anthrotech.com
----------------------


Quote Reply
Re: Total records In reply to
Thanx Eliot,

I should have seen that one, but really man I've tried Smile
Funny how more complex things go more easy than the simpler ones, sometimes.

catch