Gossamer Forum
Home : Products : DBMan : Customization :

Output to text file

Quote Reply
Output to text file
I would like to output my data to a text file or text file format, with no html. One record per line. I am using the short long mod.
Quote Reply
Re: Output to text file In reply to
Search the forum for "Printable Format".

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Output to text file In reply to
Ok found this
http://www.gossamer-threads.com/scripts/forum/resources/Forum12/HTML/000848.html

Is there a way to format the output. Have fixed width per field so it is more table like format, instead of scattered.
Quote Reply
Re: Output to text file In reply to
Yes...In the other format sub-routine, you can format the view any way you like...

For an example go here:

http://www.coco.cc.az.us/...t&sum_schedule=1

Select Art for the Subject and Session I for the Session.

Then click on the View Printable Format button.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Output to text file In reply to
Hi we want add an additional sub like the printout sub but instead of having it print to a text file we want a html sub with no headers or footers just a table like the long display. We want to print out all the records just as is happening when we sent it to the text file. How do I start this sub do I put it in the same area as the printout sub

Thanks
Quote Reply
Re: Output to text file In reply to
The better topic to use is the following:

http://www.gossamer-threads.com/...m12/HTML/000534.html

And in the sub html_print_view routine in the html.pl that is where you can put plain text with no header and footer, with the fields that you want to display.

REALLY hope this helps.

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Output to text file In reply to
Maybe I making this confusing I would like to modify the proceeding code so that i get a view in table format. Basically like the printout sub but it doesn't send the output to a text file output goes to html without the headers and footers. I want it to follow the sub printout format ie when a checkbox is checked I get all the records printed out in html table format.
Quote Reply
Re: Output to text file In reply to
How do I change this so that is prints all the records in html as apposed to output to text.


sub html_printout {
my (@hits) = @_;
my ($numhits) = ($#hits+1) / ($#db_cols+1);

$output = qq|Insert anything you want as introductory text here.
You can just put carriage returns within the text for new lines.
Be sure to end with \n\n in order to get a double space
Before the start of the record printout.|;

for (0 .. $numhits - 1) {
%rec = &array_to_hash($_, @hits);
$output .= "$rec{'Lastname'} $rec{'Firstname'} $rec{'Parents'}\n";
}
open (TEXT, ">/home/httpd/vhosts/proscouting.com/cgi-bin/data/text.txt") or
&cgierr("error in writing text file. \nReason: $!");
if ($db_use_flock) {
flock(TEXT, 2) or &cgierr("unable to get exclusive lock on text
file.\nReason: $!");
}
print TEXT $output;
close TEXT;

&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Text File Saved</title>
</head>
<body bgcolor="#DDDDDD">
<center>
<table border=1 bgcolor="#FFFFFF" cellpadding=5 cellspacing=3 width=500
align=center valign=top>
<tr><td colspan=2 bgcolor="navy">
<FONT FACE="MS Sans Serif, arial,helvetica" size=1 COLOR="#FFFFFF">
<b>$html_title: Text File Saved</b>
</td></tr>
<tr><td>
<p><center><$font_title><b>Text File Saved
</b></font></center><P>
<$font>
The text file was successfully saved.</FONT>
<P>|;
&html_footer;
print qq|</td></tr>
</table></center></body></html>|;
}
Quote Reply
Re: Output to text file In reply to
What would I remove or add in the above code

Thanks in advance
Quote Reply
Re: Output to text file In reply to
Simply add a link to the text file, like the following:

Code:
<a href="/cgi-bin/data/text.txt">View File</a>

Wink

Regards,


------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Output to text file In reply to
Oh...okay...then all you have to do is use the following codes:

Code:
sub html_printout {
#-------------------------------------------
# Print Record Routine

my (%rec) = @_; # Load any defaults to put in the VALUE field.
($db_auto_generate and print &build_html_record(%rec) and return);

print qq|
<html>
<head>
<title>Text View</title>
</head>
<body bgcolor="ffffff">
$rec{'Lastname'} $rec{'Firstname'} $rec{'Parents'}
</body>
</html>
|;
}

That is it.

Good luck!

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums


[This message has been edited by AnthroRules (edited March 09, 2000).]
Quote Reply
Re: Output to text file In reply to
 I get nothing I am not using db auto generate, am I missing some html code.

New at perl

When I put the code in the page comes back blank.

Again thanks for your help and patience



[This message has been edited by Balan (edited March 09, 2000).]
Quote Reply
Re: Output to text file In reply to
UGH....Okay...you need to use the revised codes:

Code:
sub html_printout {
#-------------------------------------------
# Print Record Routine
my (%rec) = @_; # Load any defaults to put in the VALUE field.
($db_auto_generate and print &build_html_record(%rec) and return);

&html_print_headers;
print qq|
<html>
<head>
<title>$html_title: Text View</title>
</head>
<body bgcolor="ffffff">
$rec{'Lastname'} $rec{'Firstname'} $rec{'Parents'}<br>
</body>
</html>
|;
}

Hope this works...and helps.

If not, you will have to save your html.pl and db.cgi as text files, upload them to a publicly accessible directory, and provide the URLs to these text files!

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums


[This message has been edited by AnthroRules (edited March 09, 2000).]
Quote Reply
Re: Output to text file In reply to
Hmm I have put this
<input type="checkbox" name="printout" value="1">
in sub html_search_options

In html_view_success I have the following under my (@hits) = @_;
if ($in{'printout'}) { &html_printout(@hits); return;}
At the end of the viewing section I put your code in. When I select the checkbox and select all the records. I get a blank html page.

What am I doing wrong?

Quote Reply
Re: Output to text file In reply to
The codes I've given you, and the examples I've given you ONLY work with a submit button from the search page and uses its own sub-routines in the db.cgi. I thought the other Topics were quite clear about the changes you have to make in the db.cgi, BUT I guess not...

Here are complete instructions (better bookmark this Topic in case it gets lost and I will not be posting these codes again!):

1) Add the following codes in your sub main routine in midst of the elsif statements in the db.cgi file:

Code:
elsif ($in{'printout'}) { if ($per_view) { &print_view; } else { &html_unauth; } }

2) Add the following sub-routine in your db.cgi file underneath the sub view_record:

Code:
sub print_view {
# --------------------------------------------------------
# This is called when a user is searching the database for
# viewing. All the work is done in query() and the routines just
# checks to see if the search was successful or not and returns
# the user to the appropriate page.

my ($status, @hits) = &query("view");
if ($status eq "ok") {
&html_printout(@hits);
}
else {
&html_view_failure($status);
}
}

3) Then in the html_view_search, put in the following submit button:

Code:
<input type="submit" name="print_view" value="1">

REALLY hope this works this time!

Regards,

------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Output to text file In reply to
Ok entered all this. The value you have on the new submitt does it have to be one or can i name it anything? So basically what should happen is that when I bring up the view i will have a second view button. When I click on it it should go to the sub html_printout and I should see the results. Does it matter where the sub html_printout is in the html.pl file? When I click on this second view button we need all the records in one page ie if there is 500 records we want one page with 500 records. Just one glich though I am still getting a blank page with no records just wondering if this has to do with the placement of the sub html_printout , or if I am missing something

Again thanks for your patience

Quote Reply
Re: Output to text file In reply to
 
Code:
$format_url = $ENV{'QUERY_STRING'};
$format_url =~ s/\&view_records=1/;

Then add the following link in the HTML portion of this sub:

Code:
<a href+"$db_script_url&$format_url&print_view=1">Printable View of Records</a>

Code:
open (DB, "<$db_file_name") or &cgierr("unable to open db file: $db_file
_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>;
close DB;
$number_of_records = scalar(@lines);

Then add the following codes after these codes before the my ($numhits) codes:

Code:
if ($in{'print_view'}) {
$maxhits = $number_of_records;
}

then add the following codes before my ($numhits):

Code:
else {

Then after the next line after my ($numhits), add a right bracket...

So, the codes should look like the following:

Code:
if ($in{'print_view'}) {
$maxhits = $number_of_records;
}
else {
my ($numhits) = ($#hits+1) / ($#db_cols+1);
my ($maxhits); $in{'mh'} ? ($maxhits = $in{'mh'}) : ($maxhits = $db_max_
hits);
}

And about printing the records, are you using there is one more sub-routine that you need to add called html_printout, which needs to be a copy of the sub html_view_success without the header and footer codes in it. Then replace the current sub-routine called sub html_printout to sub html_printout_record, and take out the extranous HTML codes including the <html> stuff...Just include the fields you want to print.

Then it should work.

Regards,



------------------
Eliot Lee....
Former Handle: Eliot
* Check Resource Center
* Search Forums
Quote Reply
Re: Output to text file In reply to
Thanks for your help.

If I understood this better I am sure I could make it work.

I posted a new question I hopes it explains a little better what we are trying to accomplish