473,728 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

147 New Member
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 5659
numberwhun
3,509 Recognized Expert Moderator Specialist
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 Recognized Expert New Member
Is HTML table written with Perl code? If yes, just modify it to write in different format.

Otherwise HTML::TableExtr act 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 New Member
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 New Member
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 Recognized Expert Moderator Specialist
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 New Member
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 Recognized Expert Moderator Specialist
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 New Member
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
3205
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 are older than 130 days: select count(*) from mytable where insert_date <= sysdate - 130
3
2622
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 was going to over-write the table from database B, I got an error said "You can delete table "xyz"; it is participating in one or more relationships". Can someone tell me what is the best way (safe and clean) to export all data from one Access...
1
3941
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 button, the page show the subreport detail, that's fine. but when i click the export button on crystal report tool bar, the page automatically go to the main report and export main report. Does anybod know how to do that?
0
1078
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 event,and then utilize the event's para to do more things. First ,I am not sure how much data can be exported by control event's para ? Second,I don't want to export large data by so many paras,such as largedataevent(para1,para2,para3,...... )
1
4023
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 Error 0xc0204016: DTS.Pipeline: The "output column "press_release_body" (1500)" has a length that is not valid. The length must be between 0 and 4000. (SQL Server Import and Export Wizard)
1
5662
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 this, I want DIRECTLY export what I saw in datagrid to CSV, because some of the value I changed in database before I display in the datagrid, does anyone can help me on this?
2
1861
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 Qualifier. I have about 19800 records but a few hundred are broken over multiple lines. That is, the majority of records are exported correctly but some of
3
5474
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 tried to modify the chardel to be blank, by default chardel for del is "". I tried to move it out.
12
10647
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 completed document to a variable directory based on form data. What I need to code into it now is a button that creates an email. The email has the same basic text each time but just needs to draw a
4
6129
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 files are uploading fine but Im not getting the values of the hidden fields, How can I get hidden field values along with uploaded files in the same form..?? This is my form code:
0
8894
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
8753
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9265
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9188
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9122
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8113
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 projectplanning, coding, testing, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6704
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3230
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.