Jul 10, 2003, 11:54 AM
Post #7 of 7
Okay, sorry this took so long, I have been busy! You have several things wrong with your code:
Re: [six] How do I display Records in a Table
[In reply to]
#1 all perl scripts that aren't going to be run from the command line, need to have the header line printed before you do much of anything else.
#2 you are using the strict pragma, so in your for loop, you have to declare your variable (for my $line, instead of just for $line)
#3 I don't know if you are doing this or not, but make sure that you make your html file writable, otherwise this code will not work.
#4 the loop (i think) you are trying to set up wants to read data from the .data file (@data), and then print the data to the html file (@data1). However, in your code you tell the script to loop through the lines in the html file. Well, if the html file is currently empty then nothing happens. If it does have stuff in it, it will run through the loop, but nothing will get changed. So on line 19 of the revised script (county_old.cgi) I have created, you need to change @data1 to @data.
#5 It appears that you want to grab the data from the .data file, then stick it into the .html file (nevermind the fact that each time you run this script you are going to have to re-build the database) However, for the code of mine that you are trying to adapt, you need to print only ONE table definition tag, then determine the row tags according to the number of records per row you want. Again, like I stated in the original post I made on this topic, whatever floats your boat is fine, but there are more effecient ways of displaying data. Anyway, your code is printing a new TABLE definition tag after each <!--BeginHere--> marker, but you aren't closing any of the tables, so, well, the output just looks ... bad. To fix this I cut out the TABLE definition and closing tags to outside the foreach loop.
Now we get to the topic of data display, and why it looks bad. The major reason for this is that you have set up two loops to do basically the same thing, so you end up squaring the math involved. For this test I stuck 5 records in the .data file (the data you included in your example), and using your original code it would print the data out 25 times! So I cut out the second 'for loop' you stuck in there, and created a new script (county_new.cgi) using the original foreach loop, and I just changed the split command to use the $detail variable (which already had the line data in it anyway) instead of creating a new variable ($line) for the other for loop. I also stuck a conclusion at the end of the script that tells you what happened, and provides a link to the html file.
You can see the (now working) script on my site (for a limited time) at: http://www.asayogure.com/cgi-bin/county_new.cgi
You can download the scripts and datafiles I modified for this at http://www.asayogure.com/county.zip
Hope this helps.