Gossamer Forum
Home : Products : DBMan : Customization :

Nr. of Records in static html - Gossamer -v- FlashNet

Quote Reply
Nr. of Records in static html - Gossamer -v- FlashNet
I'd been having prob's working the SSI part of displaying the Nr. of records in my database on a static html page. I've read lots of posts talking num.cgi, .shtml, ad nauseum to no avail.

So ... I asked my ISP ... below is what they say, but with "their" change to my default.cfg I get
Quote:
Error Message : Error loading required libraries.
Check that they exist, permissions are set correctly and that they compile.
Reason: Can't locate /home/m/u/murgnam/www/cgi-bin/dbmanhtml.pl in @INC (@INC contains: /home/m/u/murgnam/www/cgi-bin/dbman /usr/local/lib/perl5/sun4-solaris/5.00404 /usr/local/lib/perl5 /usr/local/lib/perl5/site_perl/sun4-solaris /usr/local/lib/perl5/site_perl .) at /home/m/u/murgnam/www/cgi-bin/dbman/default.cfg line 51.

Script Location : /home/m/u/murgnam/www/cgi-bin/dbman/db.cgi
Perl Version : 5.00404
Setup File : default.cfg
to "their" below answer
Quote:
In your default.cfg file you had the following line:

require $db_script_path . "/html.pl";

which I corrected to read:

require $db_script_path . "html.pl";

There was another error in default.cfg (line 64) which you will need to correct.
The error reads:

"Undefined subroutine &main::get_date called"

Regards,

> George,
> I only created the num.txt so you could view it publicly on the web. Even
> with me uploading num."cgi" in ASCII to my /home/m/u/murgnam/www/dbman/,
> changing to 755, still doesn't work.
> JR

--
George Marion-Landais
Flashnet Communications Internet Services
I've got num.cgi posted at http://home.flash.net/~murgnam/num.txt

Over to you Perl experts on this one. I'm sure I could prob just replace the "/" and get my database to work again (it's down for this exercise), but please translate what George may be talking about.

JR


------------------
Joebagodonuts, JR or Anita
http://home.flash.net/~murgnam/
Quote Reply
Re: Nr. of Records in static html - Gossamer -v- FlashNet In reply to
You need to do two quick things to make this script work.

First, remove the line in num.cgi that reads, require default.cfg.

Next, add a line before my $count = 0; that reads, $db_file_name = "default.db";.

The problem you were running into was that when you called default.cfg, it was requiring several additional files, and in many of those files (such as html.pl) they reference routines (such as sub get_date) only located in db.cgi; nothing requires db.cgi, as that is the primary script file.

Run your script again. It should work fine now. Smile

--Lee


[This message has been edited by leisurelee (edited April 25, 2000).]
Quote Reply
Re: Nr. of Records in static html - Gossamer -v- FlashNet In reply to
Oh yeah, and go back into your default.cfg and change that line back to require $db_script_path . "/html.pl";. Their change is bad code.

--Lee
Quote Reply
Re: Nr. of Records in static html - Gossamer -v- FlashNet In reply to
Lee,

Taking from what you said I have

1. http://home.flash.net/~murgnam/num.txt where I uploaded num."cgi" in ASCII to my /cgi-bin/dbman/

2. Put the "/" back in my default.cfg and uploaded (ASCII).

3. The static (dummy) page I'm trying to work is @ http://home.flash.net/~murgnam/80sCrowd.shtml down in the Database News you'll notice.

NOTE: The CGI tutorial @ FlashNet refers to calling SSI's as such,
Quote:
To use Server Side Includes (SSI) you make a direct call
<!--#exec cmd="/home/... (path to the cgi)..."-->
i.e. to use a counter called counter.cgi the call would be made
<!--#exec cmd="/home/w/e/webtest/www/cgi-bin/counter.cgi"-->

So ... using yr above and http://www.gossamer-threads.com/...m12/HTML/002621.html I've tried with the cmd, cgi and virtual coupled with changing the extension to *.shtml -- still no luck.

*Pulling my hair out*, but does the above help or hurt my chances?

Thx in advance.

JR
Quote Reply
Re: Nr. of Records in static html - Gossamer -v- FlashNet In reply to
Try using the following in your .shtml page:

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

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: Nr. of Records in static html - Gossamer -v- FlashNet In reply to
Joe,

Either you didn't make the changes, or you haven't updated your num.txt file. *grin* Make sure to completely remove the require line in your num.cgi file and manually define your $db_file_name.

Test your script first with your web browser. I'm not sure exactly the address, but it would be something like, http://home.flash.net/~murgnam/cgi-bin/dbman/num.cgi. If all works well, you should get a number. If there is still something wrong with the script, you'll get an error message.

If everything's OK, then you need to focus on your SSI code. I'm not very SSI-savvy, but the code examples you listed look correct.

One question, though. In your code, you said you're using <!--#exec cmd="/home/w/e/webtest/www/cgi-bin/counter.cgi"-->. Is your file counter.cgi, or num.cgi? Everywhere else, you call it num.cgi. Make sure you're executing the correct script and give it a whirl again. Let me know how it turns out!

--Lee
Quote Reply
Re: Nr. of Records in static html - Gossamer -v- FlashNet In reply to
Lee/Eliot,

1. Bonehead JR forgot to use the absolute path (SORRY Eliot).
2. With the absolute (/home/m/u/murgnam/www/cgi-bin/dbman/num.cgi), indulge me and take a look at a new (dummy) site http://home.flash.net/~murgnam/80sCrowd.htm . Note the .htm -v- .shtml extension.

With this error message, I see this as a good thing, at least the script/SSI is looking in the right place ... or is it? Should Lee's ref above be to default.db or default.cfg?

3. My database file name is default.db, and the edited num.cgi file is at http://home.flash.net/~murgnam/num.txt

4. Calling , http://home.flash.net/~murgnam/cgi-bin/dbman/num.cgi gives me "273" the exact output (# of records) I want displayed on the static html page -- so that's right, :-)

5. The reference to counter.cgi is just the "sample" FlashNet has at it's tutorial site, I'm using num.cgi.

JR
Quote Reply
Re: Nr. of Records in static html - Gossamer -v- FlashNet In reply to
I noticed that executing this script slowed down the SSI page from loading by 1 or 2 seconds, while it counted up all the records. That's not much, but can become annoying if the SSI page is reloaded alot.

I just modified the MOD code to be a LOT faster at counting the records. Here's what you'll want to do:

replace:

Code:
if (!(/^#/) && !(/^\s*$/)) {
$line = $_;
chomp ($line);
@fields = &split_decode ($line);
++$count;
}

with:

Code:
foreach (LINE) {
++$count;
}

And completely REMOVE:

Code:
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 delimiter 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;
}

This is a LOT faster. Considering every record is contained completely on its own LINE, there is no reason to split/decode them at all. This increased the script considerably.

--Lee
Quote Reply
Re: Nr. of Records in static html - Gossamer -v- FlashNet In reply to
IT WORKS IT WORKS IT WORKS!!!

Once I included the absolute paths to BOTH the $db_file_name and <!--#exec cmd="/home/m/u/murgnam/www/cgi-bin/dbman/num.cgi"-->, it actually works!!!

One note tho'. With Lee's mod to the mod, also need to take out the print "Content-type: text/html\n\n"; statement, otherwise it prints (in my case) "Content-type: text/html 273".

Above said, THANK YOU to Both Lee & Eliot ... but ONE last request. The "273" (for my purposes), how can I make that bolded on the .html page?

JR
Quote Reply
Re: Nr. of Records in static html - Gossamer -v- FlashNet In reply to
Yes, the print "Content-type: text/html\n\n"; is required if you are executing directly, like for testing purposes. Gotta comment it out to use it via SSI. Smile

To bold/underline/blink/change size/change color of the count, enclose the <--exec...--> with the HTML codes to use.

<B><U><FONT SIZE=+1 COLOR="HotPink"><!--#exec cmd="/cgi-bin/dbman/num.cgi"--></FONT></U></B>

This should do the trick. Smile

--Lee

[This message has been edited by leisurelee (edited April 25, 2000).]
Quote Reply
Re: Nr. of Records in static html - Gossamer -v- FlashNet In reply to
ugh! Back to HTML 101! That's what I get for overthinking.
Thx again.
JR
Quote Reply
Re: Nr. of Records in static html - Gossamer -v- FlashNet In reply to
Hmm...and where did you get those codes????

Wink

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: Nr. of Records in static html - Gossamer -v- FlashNet In reply to
Eliot,
I emailed Don the code. Lee's hack in this thread of your http://www.gossamer-threads.com/...m12/HTML/002621.html , got mine to working -- so I passed it to Don.
If I misspoke I apologize, but it works for me, <g>.
JR
Quote Reply
Re: Nr. of Records in static html - Gossamer -v- FlashNet In reply to
Is the num.cgi a script that is available somewhere? I looked in the resource area and didn't see it?
Quote Reply
Re: Nr. of Records in static html - Gossamer -v- FlashNet In reply to
Ooops - nevermind found it.
Quote Reply
Re: Nr. of Records in static html - Gossamer -v- FlashNet In reply to
Joe's got the num.cgi linked from here, but should he remove it, here's the code as it should be:

Code:
#!/usr/local/bin/perl
# Number of Records
$db_file_name = "/path/to/dbman/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;
# Uncomment this line to execute directly.
# Comment it to use in an SSI.
# 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;
}

Then in your .shtml page, place the following code to call the script:

Code:
<!--#exec cmd="/path/to/num.cgi"-->

--Lee
Quote Reply
Re: Nr. of Records in static html - Gossamer -v- FlashNet In reply to
No sweat. Actually, I got the codes from joe's link on this page. I didn't know what thread they were from, so that was all I had to work with. Smile

--Lee
Quote Reply
Re: Nr. of Records in static html - Gossamer -v- FlashNet In reply to
erhhh
i keep getting error

CGI ERROR
==========================================
Error Message: error in Number of Records. unable to open database:/cgi-bin/db/default.db.
Reason: !
Script Location: num.cgi
Perl Version: 5.00502

any idea please???
thanks!!

for the file name, does it have to be the absolute path of the file??
here is what i put:

$db_file_name = "/cgi-bin/db/default.db";

Quote Reply
Re: Nr. of Records in static html - Gossamer -v- FlashNet In reply to
If you just want a simple count of the number of records in your database use the following:
Name it count.cgi and chmod it to 644

#!/usr/local/bin/perl

#### print number of record in database

print "Content-type: text/html\n\n";

## open (DB, "/path/to/default.db") or print "Cant' find db!";
### use above if it's not in the same directory as your db. file.

open (DB, "auto.db") or print "Cant' find db!"; ### change this line to the name of the database file
while (<DB> ) { $count ; }
close DB;
print $count;
1;

I've edited this post 6 times and it keeps leaving off the virtual include command? But that is what you would try to use first when calling the script.
Quote Reply
Re: Nr. of Records in static html - Gossamer -v- FlashNet In reply to
I must be very stupid
cant even get this thing to work

#!/usr/local/bin/perl

#### print number of record in database

print "Content-type: text/html\n\n";

## open (DB, "/path/to/default.db") or print "Cant' find db!";
### use above if it's not in the same directory as your db. file.

open (DB, "default.db") or print "Cant' find db!"; ### change this line to the name of the database file
while (<DB> ) { $count ; }
close DB;
print $count;
1;

i place the count.cgi in the smae folder as the db file
then


place my shtml fil under the www root


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Untitled</title>
</head>

<body>



</html>

none of those 2 command above worked....

sorry but please help :(


Quote Reply
Re: Nr. of Records in static html - Gossamer -v- FlashNet In reply to
I would check with your host provider and see if they have a faq for using ssi commands.

Server hosts do vary in what commands work best with their servers. Try:

include virtual
exec cgi
exec cmd

perhaps one of those will work. If not, I would contact your host provider for advice on using SSI commands.

Don't forget that even if you have the .cgi file in the same directory, that your web page is up a directory or two. So if you directory structure is: /cgi-bin/dbman/ and your web page is in your root directory then you would use:

include virtual="../cgi-bin/count.cgi"

or you could try the full path to your dbman directory.