473,395 Members | 1,941 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to export form data to CSV with perl-cgi ?

147 100+
Hello,

I currently have an HTML table with data in it. The data comes from SQL2000. I want to take my HTML table and allow users to hit an "Export to CSV" button which will allow them to download the data in the table to a file.I am unfamiliar with this, and haven't done much file writing/reading stuff in Perl. I've searched the web and have been unable to find a good solution/example for this problem. Help is appreciated! thanks...give me coding on this
Jan 10 '11 #1
8 5631
numberwhun
3,509 Expert Mod 2GB
I would certainly search Google to find information on reading/writing files. Its not that bad, really.

You may also want to investigate the use of modules to help with your solution writing. If you get stuck, post your questions here and we will help you.

Regards,

Jeff
Jan 10 '11 #2
chorny
80 Expert
Is HTML table written with Perl code? If yes, just modify it to write in different format.

Otherwise HTML::TableExtract from CPAN may help you.

P.S. Consider reading "Learning Perl" (no earlier than 4th edition) or "Beginning Perl".
Jan 11 '11 #3
santhanalakshmi
147 100+
Hi,
I don't know, how to start? For CSV export on client machine, there is need to use DBI::CVS.

My Perl output is in table format(used HTML also, datas coming from SQL 2000). I need this output in my client machine as CSV. Your Help is in need. Thanks in advance.
Jan 11 '11 #4
santhanalakshmi
147 100+
Hi,
Thanks for your reply. Yes, it is HTML Table. Hi,
I don't know, how to start? For CSV export on client machine, there is need to use DBI::CVS.

My Perl output is in table format(used HTML also, datas coming from SQL 2000). I need this output in my client machine as CSV.
Jan 11 '11 #5
numberwhun
3,509 Expert Mod 2GB
Ok, so the data was pulled from the database prior to being put into table format. You should be able to take that data and also output it to CSV format.

If there is already a DBD module used to connect to the SQL2000 database and pull the data, I don't know what the implications would be of attempting to use a second DBD module. It may possibly cause a conflict.

Instead, you may want to look into using something like the Class::CSV module to write your CSV file instead. I have never used it, but just searched for csv on search.cpan.org and found it.

If I were you, I would also look into the Learning Perl book that @chorny suggested. IMHO, it is one of the better books out there as a beginning Perl tutorial.

If you want further help with any code, it will be of great help if you could paste your code here so we can see it and help you with it.

Regards,

Jeff
Jan 11 '11 #6
santhanalakshmi
147 100+
Hi,
Thanks. Please see my output. Currently i am getting this output in my form:

sno name location cgpa
1 sss chennai 8.9
2 aaa bombay 7.2


My coding:
1.
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use warnings;
  3. use strict;
  4.  
2. Opening HTML Tag
3. Opening Table Property (HTML)
4. Connecting to my database:
using my
Expand|Select|Wrap|Line Numbers
  1. sth->connect(DBI:dns:loginname:password)
5. Picking up the data from my database.
6. Doing some operation here
7. Submit Button
8. Closing Table Tag (is in HTML)
9. Closing HTML.

By clicking the Submit Button, i am getting the following output as shown above in all my client machine.

I need one more button to generate this output in CSV file(this should work globally all my client machines). Please do a favour or give me a solution to proceed this. thanks
Jan 11 '11 #7
numberwhun
3,509 Expert Mod 2GB
Please know that when I said, paste your code in, I was referring to the actual code, not the code walk through. Do you actually have any code written or are you not really able to provide it?
Jan 11 '11 #8
santhanalakshmi
147 100+
Expand|Select|Wrap|Line Numbers
  1. #!c:/perl/bin/perl
  2. use CGI qw(:all);
  3. $pdeptcode=uc(param('deptcode'));
  4.  
  5. $pperiod=uc(param('period'));
  6.  
  7. $pprogramme=uc(param('prg'));
  8.  
  9.  
  10. print "Content-type: text/html\n\n";
  11. print "<body bgcolor=\"#ffcccc\">";
  12.  
  13. use DBI;
  14. my $dbh = DBI->connect("DBI:ODBC:aaaa","bbb","cccc") or die "Can not connect: $DBI::errstr\n"; 
  15.  
  16. my $sth;
  17.  
  18. print "<center><table border=1></center>";
  19. print "<tr><th>SlNo</th><th>Roll Number</th><th>Name</th><th>Branch Name</th></tr>";
  20.  
  21.     if (($pperiod eq 'ALL') && ($pdeptcode ne 'ALL') && ($pprogramme ne 'ALL'))
  22.     {
  23.                $sth=$dbh->prepare("select a.rollno,a.name,b.branname from stuacmst a,brnchmst b where a.deptcode=? and a.programme=? and  a.studstat in ('C','F') and a.brancode=b.brancode order by a.rollno");
  24.              $sth->execute($pdeptcode,$pprogramme) or die "Cant execute SQL: $DBI::errstr\n";
  25.       }
  26.  
  27.       if (($pperiod ne 'ALL') && ($pdeptcode eq 'ALL') && ($pprogramme ne 'ALL'))
  28.     {
  29.  
  30.                $sth=$dbh->prepare("select a.rollno,a.name,b.branname from stuacmst a,brnchmst b where a.semester=? and a.programme=? and  a.studstat in ('C','F') and a.brancode=b.brancode order by a.rollno");
  31.              $sth->execute($pperiod,$pprogramme) or die "Cant execute SQL: $DBI::errstr\n";
  32.       }
  33.        if (($pperiod ne 'ALL') && ($pdeptcode ne 'ALL') && ($pprogramme eq 'ALL'))
  34.     {
  35.  
  36.                $sth=$dbh->prepare("select a.rollno,a.name,b.branname from stuacmst a,brnchmst b where a.semester=? and a.deptcode=? and  a.studstat in ('C','F') and a.brancode=b.brancode order by a.rollno");
  37.              $sth->execute($pperiod,$pdeptcode) or die "Cant execute SQL: $DBI::errstr\n";
  38.       }
  39.  
  40.  
  41.        if (($pperiod eq 'ALL') && ($pdeptcode eq 'ALL') && ($pprogramme ne 'ALL'))
  42.     {
  43.  
  44.                $sth=$dbh->prepare("select a.rollno,a.name,b.branname from stuacmst a,brnchmst b where a.programme=? and  a.studstat in ('C','F') and a.brancode=b.brancode order by a.rollno");
  45.              $sth->execute($pprogramme) or die "Cant execute SQL: $DBI::errstr\n";
  46.       }
  47.  
  48.  
  49.       if (($pperiod eq 'ALL') && ($pdeptcode ne 'ALL') && ($pprogramme eq 'ALL'))
  50.     {
  51.  
  52.                $sth=$dbh->prepare("select a.rollno,a.name,b.branname from stuacmst a,brnchmst b where a.deptcode=? and  a.studstat in ('C','F') and a.brancode=b.brancode order by a.rollno");
  53.              $sth->execute($pdeptcode) or die "Cant execute SQL: $DBI::errstr\n";
  54.       }
  55.  
  56.  
  57.        if (($pperiod ne 'ALL') && ($pdeptcode eq 'ALL') && ($pprogramme eq 'ALL'))
  58.     {
  59.  
  60.                $sth=$dbh->prepare("select a.rollno,a.name,b.branname from stuacmst a,brnchmst b where a.semester=? and  a.studstat in ('C','F') and a.brancode=b.brancode order by a.rollno");
  61.              $sth->execute($pperiod) or die "Cant execute SQL: $DBI::errstr\n";
  62.       }
  63.  
  64.  
  65.        if (($pperiod eq 'ALL') && ($pdeptcode eq 'ALL') && ($pprogramme eq 'ALL'))
  66.     {
  67.             $sth=$dbh->prepare("select a.rollno,a.name,b.branname from stuacmst a,brnchmst b where a.studstat in ('C','F') and a.brancode=b.brancode order by a.rollno");
  68.              $sth->execute or die "Cant execute SQL: $DBI::errstr\n";
  69.       }
  70.  
  71.        if (($pperiod ne 'ALL') && ($pdeptcode ne 'ALL') && ($pprogramme ne 'ALL'))
  72.     {
  73.  
  74.             $sth=$dbh->prepare("select a.rollno,a.name,b.branname from stuacmst a,brnchmst b where a.semester=? and a.deptcode=? and a.programme=? and  a.studstat in ('C','F') and a.brancode=b.brancode order by a.rollno");
  75.              $sth->execute($pperiod,$pdeptcode,$pprogramme) or die "Cant execute SQL: $DBI::errstr\n";
  76.       }
  77.  
  78.     while ( @row = $sth->fetchrow_array())
  79.     {
  80.           $j=$j+1;
  81.           print "<tr><td>$j</td><td>$row[0]</td><td>$row[1]</td><td>$row[2]</td></tr>";
  82.     }
  83.  
  84. print "</table>";
  85. print "<br>";
  86. print "</html>";
  87.  
  88.  
Hi, please see my coding. Thanks for your effort.
Jan 12 '11 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: DMina | last post by:
Hello people! I am a bit puzzled here so any help will be much appreciated. Here is the situation: I have a query which selects all the data based on a date column. I need all the data which...
3
by: eddie wang | last post by:
Hello, I am trying to export all the data from one Access database to another Access database. I selected one of my five tables, then clicked "File"-->"Export". Because my table from database A...
1
by: John | last post by:
Hi. Sir: Does anyboday know how to export subreport data using the export button in crystal report tool bar? We have a main report including a on-demand report. When we click the on-demand...
0
by: 詹亚军 | last post by:
can activex control export large data to container by event's para ? I develop a activex control,and want to export large data to container(IE),web page can use javascript to capture the...
1
by: Mindaugas | last post by:
I'm trying to help a client export some data from SQL 2005 to an Access database or even an Excel file. Either way I get an error like this: - Setting Destination Connection (Error) Messages...
1
by: johnlim20088 | last post by:
Hi All, I does have a question about export datagrid data to csv. Well, I know the common solution is 1) select the data again and put in the datatable, then export to csv. BUT I don't want...
2
by: Sashi | last post by:
Hi All, I have a table from which I want to export the data as a plain text file. I exported the data using the "Export" option and selected the comma as a separator and the " as the Text...
3
by: zhif | last post by:
Hello everybody, I am trying to export the data from DB2 database to MySQL. The command I used is db2 "export to sys_state.del of del modified coldel; select * from sys_state" But, I...
12
by: DeZZar | last post by:
Hi all, I'll explain my database first. Users input customer details that are required to complete a company document. The document merge etc is all working - the database saves the...
4
by: virtualweb | last post by:
Not able to pass variables data: Hello .. Im building a form that uploads files with encType="multipart/form-data" but on the same form I need to pass other variables with hidden fields. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.