473,386 Members | 1,733 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,386 software developers and data experts.

Using CGI to print a table

Ganon11
3,652 Expert 2GB
Hey everyone,

For a class assignment, I am making a class scheduling CGI program/script. I have everything working so far except actually displaying the schedule as a grid/2D table. I am not very proficient in HTML, let alone Perl making HTML, so I tried to grab some code I found online and found two issues:

1) In the following code:

Expand|Select|Wrap|Line Numbers
  1. print table({-border=>undef},
  2.            caption('Class Schedule'),
  3.            Tr({-align=>CENTER,-valign=>TOP},
  4.            [
  5.               th(\@headers),
  6.               td(\@AM_8),
  7.               td(\@AM_9),
  8.               td(\@AM_10),
  9.               td(\@AM_11),
  10.               td(\@PM_12),
  11.               td(\@PM_1),
  12.               td(\@PM_2),
  13.               td(\@PM_3),
  14.               td(\@PM_4),
  15.               td(\@PM_5),
  16.               td(\@PM_6),
  17.               td(\@PM_7),
  18.               td(\@PM_8),
  19.               td(\@PM_9)
  20.            ]
  21.            )
  22.         ), p;
my CGI page tells me it cannot recognize the CENTER or TOP keywords, and will not print anything. Not a big deal - I can delete that portion and the errors will end.

2) I am building @AM_8, @AM_9, etc. in the following manner:

Expand|Select|Wrap|Line Numbers
  1. my (
  2.    @AM_8, 
  3.    @AM_9, #etc etc etc...all the way up to @PM_9
  4. ) = (
  5.    ('8 AM', ' ', ' ', ' ', ' ', ' '), 
  6.    ('9 AM', ' ', ' ', ' ', ' ', ' '), #etc etc etc...for each array
  7. );
  8.  
  9. for my $class (@master_class_list) {
  10.         my $class_desc = $class->NAME . ", Room " . $class->ROOM;
  11.         if ($class->START_TIME == 1) {    # Only way this class could be at 8 is if it starts at 8
  12.             if (array_contains("Monday", @{$class->DAYS})) {
  13.                 $AM_8[1] = $class_desc;
  14.             }
  15.             if (array_contains("Tuesday", @{$class->DAYS})) {
  16.                 $AM_8[2] = $class_desc;
  17.             }
  18.             if (array_contains("Wednesday", @{$class->DAYS})) {
  19.                 $AM_8[3] = $class_desc;
  20.             }
  21.             if (array_contains("Thursday", @{$class->DAYS})) {
  22.                 $AM_8[4] = $class_desc;
  23.             }
  24.             if (array_contains("Friday", @{$class->DAYS})) {
  25.                 $AM_8[5] = $class_desc;
  26.             }
  27.         }
  28.                 # And so on and so forth, for each time period.
I realize this is incredibly tedious, but I don't know how to print the table any better.

Anyway, after building the list like that, I printed the table (using the code from (1)), and got horribly incorrect output. I changed the code to

Expand|Select|Wrap|Line Numbers
  1. print table({-border=>undef},
  2.            caption('Class Schedule'),
  3.            Tr(
  4.            [
  5.               th(\@headers),
  6.               td(\@AM_8)
  7.            ]
  8.            )
  9.         ), p;
to see if I could narrow down the problem, and got this as my output:

http://i295.photobucket.com/albums/m...RONG_WRONG.jpg

I do not understand this in the least. I am no longer printing ANYTHING containing '9 AM', '10 AM', etc., yet they are still being output. I would like to have a 2D grid with days across the top (as shown) and times along the left side. Any advice on how to do this?

This is a homework assignment due Tuesday night, and this is only a small portion. If I can't figure this out by Tuesday night, I'll just print all the class information, which will at least get me partial credit, but I'd like to get this table working.

Any help is MUCH appreciated!
Apr 20 '08 #1
3 1857
KevinADC
4,059 Expert 2GB
my CGI page tells me it cannot recognize the CENTER or TOP keywords, and will not print anything. Not a big deal - I can delete that portion and the errors will end.
You need to quote those words, since they are just simple strings use single-quotes:

Expand|Select|Wrap|Line Numbers
  1. Tr({-align=>'CENTER',-valign=>'TOP'},
Apr 20 '08 #2
KevinADC
4,059 Expert 2GB
The thing to do to look at why your html is not what you expect is examine the html source code. Then modify your perl code that generates the html accordingly.

Your perl code is quite confusing and therefore there is no way to help determine if it is contribuitng to the problem or if it is a simple html problem.
Apr 20 '08 #3
Ganon11
3,652 Expert 2GB
Kevin,

Thanks for the reply, both problems have been solved. It turns out the initialization list for my arrays was flattening out and filling @AM_8 with everything. Separating the declarations into different lines solved that issue.

I also agree that this code is a huge mess. Unfortunately, I am terrible at HTML, and thus terrible at generating HTML with Perl, so this is the best I can do for code simplicity.
Apr 20 '08 #4

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

Similar topics

4
by: Anshul Gupta | last post by:
Hi, Is there a way i can just print a designated area out of the whole asp(or html) page using javascript or vbscript. i want to mark out the beginning and the end on the page and create a link...
4
by: banz | last post by:
Hello I have a problem to resolve: I wrote a Perlscript which caches data from a server (local on my machine) I would like to have a other connection to a remote server but I don't know how to...
0
by: Michelle Keys | last post by:
I am trying to call a print function to print a string from a database using javascript. Which is RC_DATA of Varchar2(2500). This is a javascript is not being used. I have a thing that needs to...
5
by: cover | last post by:
I have an input form that passes data when submitted to a second form to let the user know what they have just entered into the db. My question comes with using 'update'. I'd like to query the...
3
by: focussys | last post by:
hi i am a student and am doing this for one of my assignments i am trying to create a login using perl and mysql database.i was succesful in doing that now i want to use cookies for...
0
by: supern | last post by:
this is my perl script saved as login.pl #!c:/perl/bin/perl.exe $basedir="c:/program files/apache software foundation/apache2.2/cgi-bin"; $datafile="regstr.txt"; $name=$in{'login'};...
14
by: jcage | last post by:
Is there any tutorials online for sending email through forms? I can send an email as well as write to my MySQL database from home with the following code but not at work. I think there might be...
0
by: Nathan Harmston | last post by:
HI, I posted this to sqlalchemy but didnt get a response, so I was wondering if anyone on python-list could help me. I m currently trying to build an api for a database and I really like the...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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,...
0
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...
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...

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.