Gossamer Forum
Home : Products : DBMan : Customization :

showing number of records in a static page

Quote Reply
showing number of records in a static page
How can I use a sentence like "There are ### records in this database" in a static page where ### is really the number of records in my dbman database.

Just like after a * search the database says "Your search returned ### records"
Quote Reply
Re: showing number of records in a static page In reply to
* You will have to use SSI and use the following script...

Look at April 13,2000 Reply for Codes

* Name this script something like num.cgi. Upload it to your server. And change the permission of this file to 755 (rwxr-xr-x).

Note: Don't forget to change /absolute/path/to to the absolute path where your default.cfg and db.cgi files are located.

* Then use one of the following SSI calls in your SSI enabled web page:

Code:
<!--#exec cgi="/cgi-bin/dbman/num.cgi"-->

-OR-

Code:
<!--#include virtual="/cgi-bin/dbman/num.cgi"-->

Regards,


------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.


[This message has been edited by AnthroRules (edited April 11, 2000).]

[This message has been edited by AnthroRules (edited April 13, 2000).]
Quote Reply
Re: showing number of records in a static page In reply to
Thanks Eliot. One of these days I'm going to have to learn about SSI. But as long as you're here, I don't have to worry about it. Smile


------------------
JPD






Quote Reply
Re: showing number of records in a static page In reply to
You're welcome...Glad to help.

Smile

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.
Quote Reply
Re: showing number of records in a static page In reply to
Thank you very much.
I tried the script but I couldn't get it working.
I have modified the num script to show the required files.
But when I call it I get the contents of sub html_home in my html.pl file.

What might be the problem?
Quote Reply
Re: showing number of records in a static page In reply to
Look at April 13,2000 Reply for Codes

Regards,
------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.


[This message has been edited by AnthroRules (edited April 13, 2000).]
Quote Reply
Re: showing number of records in a static page In reply to
One thing to remember, not sure if this is just obvious or if it should be mentioned. Smile

For your SSI static page, make sure it is .shtml. Also make sure your server allows Server Side Includes. Some web servers don't, for security matters.

--Lee

P.s., I just re-read the thread, and figured out this has nothing to do with anything. LOL. But, I'll leave it, in case anyone else has problems.

[This message has been edited by leisurelee (edited April 12, 2000).]
Quote Reply
Re: showing number of records in a static page In reply to
 
Quote:
For your SSI static page, make sure it is .shtml.

And this statement is NOT correct. You do not have to have the .shtml extension for SSI to work with a server that allows SSI. You can edit the .htaccess file for UNIX and edit the Script Mapping Configurations for NT to allow .html and .htm files to also execute SSI calls.

Wink

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.
Quote Reply
Re: showing number of records in a static page In reply to
This revision solved the first problem but (as always Smile) there is one more problem.

To make you sure I'm using an SSI enabled server and the page's name is dene.shtml.

The error I'm getting is :
[error] malformed header from script. Bad header=11227: /usr/local/etc/httpd/vhosts/surpluscat.com/cgi-bin/sayi.cgi

11227 is really the number of records in my database. And it doesn't show on the .shtml page.

Thanks.. Bye..
Quote Reply
Re: showing number of records in a static page In reply to
Oopss...forgot to add the Content/HTML line...

So, here are the revised codes:

Code:
#!/usr/local/bin/perl
# Number of Records
require "/absolute/path/to/default.cfg";
my $count = 0;
open (DB, "<$db_file_name") or
&cgierr("error in number of records. unable to open database:$db_file_name.\nReason:
$!");
LINE: while (<DB> ) {
if (!(/^#/) && !(/^\s*$/)) {
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
++$count;
}
}
close DB;
print "Content-type: text/html\n\n";
print $count;
sub split_decode {
# --------------------------------------------------------
# Takes one line of the database as input and returns an
# array of all the values. It replaces special mark up that
# join_encode makes such as replacing the '``' symbol with a
# newline and the '~~' symbol with a database delimeter.
my ($input) = shift;
$input =~ s/\Q$db_delim\E$/$db_delim /o; # Add a space if we have delimi
ter new line.
my (@array) = split (/\Q$db_delim\E/o, $input);
for ($i = 0; $i <= $#array; $i++) {
$array[$i] =~ s/~~/$db_delim/og; # Retrieve Delimiter..
$array[$i] =~ s/``/\n/g; # Change '' back
to newlines..
}
return @array;
}
sub cgierr {
# --------------------------------------------------------
# Displays any errors and prints out FORM and ENVIRONMENT
# information. Useful for debugging.
if (!$html_headers_printed) {
print "Content-type: text/html\n\n";
$html_headers_printed = 1;
}
print "<PRE>\n\nCGI ERROR\n==========================================\n"
;
$_[0] and print "Error Message : $_[0]\n";
$0 and print "Script Location : $0\n";
$] and print "Perl Version : $]\n";
$db_setup and print "Setup File : $db_setup.cfg\n";
$db_userid and print "User ID : $db_userid\n";
$db_uid and print "Session ID : $db_uid\n";
print "\nForm Variables\n-------------------------------------------\n";
foreach $key (sort keys %in) {
my $space = " " x (20 - length($key));
print "$key$space: $in{$key}\n";
}
print "\nEnvironment Variables\n----------------------------------------
---\n";
foreach $env (sort keys %ENV) {
my $space = " " x (20 - length($env));
print "$env$space: $ENV{$env}\n";
}
print "\n</PRE>";
exit -1;
}

That should do it...

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.


[This message has been edited by AnthroRules (edited April 13, 2000).]
Quote Reply
Re: showing number of records in a static page In reply to
.shtml may not be required, but it is a standard. For those that don't have administrator control of their servers and don't have the luxury or know-how of hacking their configurations, they'll probably have to use .shtml extensions.

But, like I said. it is a standard. Nothing is stopping you from coloring outside the lines, but your picture will look better if you stay inside them.

--Lee
Quote Reply
Re: showing number of records in a static page In reply to
Yesssss it's done.

Thank BOTH of you !!! Smile)

Quote Reply
Re: showing number of records in a static page In reply to
You're welcome.

Quote:
Thank BOTH of you...

Who else helped you???

Wink

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.
Quote Reply
Re: showing number of records in a static page In reply to
I believe I did. But not very much! Eliot did most of the grunt-work. Smile

You're welcome. Glad it worked!!

--Lee
Quote Reply
Re: showing number of records in a static page In reply to
donm,

You did not copy the complete codes that I posted in this Topic.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
Anthro TECH, L.L.C
anthrotech.com
* Check Resource Center
* Search Forums
* Thinking out of the box (codes) is not only fun, but effective.


Quote Reply
Re: showing number of records in a static page In reply to
ok - I have tried this - but keep getting the same error virago was:

Code:
malformed header from script. Bad header=491: /home/WWW10/melhialumni.com/cgi-bin/dbtest/count.cgi

Here is the code that I am using:

Code:
#!/usr/bin/perl -w
# Number of Records

# Absolute path to database
$db_file_name = "/home/WWW10/melhialumni.com/cgi-bin/dbtest/default.db";
my $count = 0;
open (DB, "<$db_file_name") or
&cgierr("error in number of records. unable to open database:$db_file_name.\nReason:
$!");
LINE: while (<DB> ) {
foreach (LINE) {++$count;
}
}
close DB;
print "Content-type: text/html\n\n";
print $count;

sub cgierr {
# --------------------------------------------------------
# Displays any errors and prints out FORM and ENVIRONMENT
# information. Useful for debugging.
if (!$html_headers_printed) {
print "Content-type: text/html\n\n";
$html_headers_printed = 1;
}
print "<PRE>\n\nCGI ERROR\n==========================================\n";
$_[0] and print "Error Message: $_[0]\n";
$0 and print "Script Location: $0\n";
$] and print "Perl Version: $]\n";
$db_setup and print "Setup File: $db_setup.cfg\n";
$db_userid and print "User ID: $db_userid\n";
$db_uid and print "Session ID: $db_uid\n";
print "\nForm Variables\n-------------------------------------------\n";
foreach $key (sort keys %in) {
my $space = " " x (20 - length($key));
print "$key$space: $in{$key}\n";
}
print "\nEnvironment Variables\n-------------------------------------------\n";
foreach $env (sort keys %ENV) {
my $space = " " x (20 - length($env));
print "$env$space: $ENV{$env}\n";
}
print "\n</PRE>";
exit -1;
}

-----------------------
donm

[This message has been edited by donm (edited May 02, 2000).]
Quote Reply
Re: showing number of records in a static page In reply to
From what you've posted..

looks like you missed the 'sub split_decode' routine Smile

but I could be wrong Smile

------------------
-----------
millsie :)

A smile a day...
keeps the viri' away.
Quote Reply
Re: showing number of records in a static page In reply to
Don,
You know I'm NO Perl expert, but appears your error message is pulling off of "count".cgi -v- "num".cgi, :-0.
JR
Quote Reply
Re: showing number of records in a static page In reply to
You are right I am using code that Joe gave to me ( a modified version of what you have written).

I did finally get it working - I had a bad SSI call on the .shtml page.

Thanks all !

-----------------
donm

[This message has been edited by donm (edited May 02, 2000).]