473,395 Members | 1,742 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.

Script to build html page with table containing pictures

I am a novice Perl programmer and need to change a perl script that I use to create web pages with thumbnail images and some text. Currently the script created a web page for each artist / category with all the thumb images below one another in the table. Thus the table has one column with a row for each image.

I am trying to change the script to have 3 columns in the table in the end (first testing with second column as in the attached script). The first row is filled with thumb images and text before the second row is filled etc.

I just cannot get the script to create the second column with the images etc.

I will really appreciate any help on this matter. If this problem is not suitable for the forum I appologise but will really appreciate it if a Perl programmer can contact me in this regard.

The script follows:

Expand|Select|Wrap|Line Numbers
  1. # Stystem to build thumbnail image pages from data file
  2. # (Use htmlkop and htmlstert files for the start and end of each html file)
  3.  
  4. #Set the Parameters
  5.  
  6. $meesterdir = 'C:\F\Websites\Johan Smith NEW\artwork\thumbshtml'; #Directory where HTML is written to
  7. $datatabel = 'C:\F\Websites\Johan Smith NEW\artwork\datafile\datafile.txt'; #Directory were data file is
  8. $tumbsdir = 'C:\F\Websites\Johan Smith NEW\artwork\htmlcategory'; #Directory were thumbs page that is being created will be saved
  9. # print "$meesterdir\n";
  10.  
  11. #
  12.  
  13. #$htmlkop is the top part of HTML page
  14.  
  15. $htmlkopleer = 'C:\F\Websites\Johan Smith NEW\artwork\htmlkopthumbsnew.txt'; # File where htmlkop of the thumbs page is
  16. #sleep(1);
  17. # HTML kop
  18. $fx ='';
  19. open (LEER, $htmlkopleer) || the "Cannot open $htmlkopleer \n";
  20. while (<LEER>) {$fx .=$_};
  21. close (LEER);
  22.  
  23. #print $fx;
  24. $htmlkop = $fx;
  25. #print "$htmlkop\n";
  26. sleep(1);
  27.  
  28. $htmlstertleer='C:\F\Websites\Johan Smith NEW\artwork\htmlstertthumbs.txt'; # File where htmlstert of the thumbs page is
  29.  
  30. # HTML stert
  31. $fx ='';
  32.  
  33. open (LEER, $htmlstertleer) || the "Cannot open $htmlstert \n";
  34. while (<LEER>) {$fx .=$_};
  35. close (LEER);
  36.  
  37. #print $fx;
  38. $htmlstert = $fx;
  39. #print "$htmlstert\n";
  40. sleep(1);
  41.  
  42.  
  43. #
  44. # Now the data file is read to go further
  45.  
  46. #Each category is for a different artist for which we want to build a html page with all the thumnails and info of his works
  47.  
  48. %category = (
  49.     'adriaanboshoff'    => 'Adriaan Boshoff',
  50.     'alanainslie'        => 'Alan Ainslie',
  51.     'johansmith'        => 'Johan Smith',
  52. ); # end of list
  53.  
  54. #print $category; #Show category on screen to show what was done, this is just for testing the script.
  55. sleep(1);
  56.  
  57. #foreach $katelem (keys(%category)) {print "test $katelem $category{$katelem}\n";sleep(5)}
  58.  
  59. foreach $katelem (keys(%category)) {
  60.  
  61.     $catleernaam = $katelem;
  62.  
  63.     # print "$catleernaam\n"; #Show catleernaam on screen to indicate that step was done - only for testing
  64.     # sleep(1);
  65.  
  66.  
  67.     sleep(1);
  68.  
  69.     #$category='';
  70.     $subcategory= '';
  71.  
  72.  
  73.  
  74.  
  75.     $thumbleer = $tumbsdir.'\\'.$catleernaam.'.html';
  76.     print "$thumbleer thumbleer\n\n";
  77.  
  78.     open (THUMBS,">$thumbleer") || die "kan nie thumb oopmaak nie
  79.     $thumbleer\n";
  80.  
  81.     # Change <%cat_title%> with name of artist
  82.     #print "$katelem $category{$katelem} wie\n";
  83.  
  84.     $htmlkopb = $htmlkop;
  85.     $htmlkopb =~ s/<%cat_title%>/$category{$katelem}/;
  86.  
  87.     print THUMBS $htmlkopb;
  88.  
  89.  
  90.     # =========================================================
  91.     # From here the data line is read from data file and a test is done to see if it is still the same artist.
  92.     # =========================================================
  93.     open (LEER2, $datatabel) || the "cannot open data table
  94.     $datatabel oopmaak nie\n";
  95.     while (<LEER2>){
  96.         $ding3=$_;
  97.  
  98.         chop($ding3); # Abstract one record line uit data table (file datafile.txt)
  99.         @velde = split(/%|%/,$ding3); # Split fields of each record at each %|%
  100.  
  101.         if ($velde[24] eq $katelem) {
  102.  
  103.  
  104.             # Start of cell 1 contents ========================
  105.             print THUMBS "<tr><td align=center><font size=1><a href=\"../htmldetail/$velde[0]/index.html\"\><img
  106. src=\"../htmldetail/$velde[0]/$velde[0]thumb.jpg\" align=center
  107. alt=\"Click for more\"></a></font><br><font color=#ffffff align=center><span style=\"font-size: 8pt;\">$velde[12]</strong><br><br>
  108. </font>
  109. </span>
  110. </td>"; #Cell 1 end
  111.             print THUMBS "";
  112.             sleep(1);
  113.  
  114. # -----------------------------------------------------------------------------------------
  115. # Cell 2 in the same row
  116.  
  117.             open (LEER2, $datatabel) || the "cannot open data table $datatabel \n";
  118.             while (<LEER2>) {
  119.                 $ding3=$_;
  120.  
  121.                 chop($ding3); # Abstract one record line uit data table (file datafile.txt)
  122.                 @velde = split(/%|%/,$ding3); # Split fields of each record at each %|%
  123.  
  124.                 if ($velde[24] eq $katelem) {
  125.  
  126.  
  127.                     # Start cell 2 contents ========================
  128.                     print THUMBS "<tr><td align=center><font size=1><a href=\"../htmldetail/$velde[0]/index.html\"\><img
  129. src=\"../htmldetail/$velde[0]/$velde[0]thumb.jpg\" align=center
  130. alt=\"Click for more\"></a></font><br><font color=#ffffff align=center><span style=\"font-size: 8pt;\">$velde[12]</strong><br><br>
  131. </font>
  132. </span>
  133. </td>"; #Cell 2 end
  134.                     print THUMBS "";
  135.  
  136. # --------------------------------------------------------------------------------------
  137.  
  138.  
  139.  
  140.                 } ;#end if;
  141.             }; # End while leer2
  142.  
  143.             close (LEER2);
  144.             print THUMBS "$htmlstert";
  145.             close (thumbs);
  146.         } # End foreach $katelem
  147.  
Apr 14 '07 #1
7 3364
KevinADC
4,059 Expert 2GB
Maybe the word "the" in some lines should be "die", for example:

Expand|Select|Wrap|Line Numbers
  1. open (LEER, $htmlkopleer) || the "Cannot open $htmlkopleer \n";
and there are several more lines like that. You can also add "$!" to die lines to get the specific error returned by the operating system:

Expand|Select|Wrap|Line Numbers
  1. open (LEER, $htmlkopleer) || die "Cannot open $htmlkopleer: $!\n";
Apr 14 '07 #2
miller
1,089 Expert 1GB
Hi Mariusf

I've editted your post to enclose your script in a "CODE" tag, and also to add tabbed formatting. I noticed that your brackets are currently not balanced. Your missing closing brackets in at least 2 places, so I suggest that you go through your code and fix these things.

If you're still having problems after you do that, then repost your new code in a CODE tag, and we'll talk another look.

- Miller
Apr 14 '07 #3
Hi Mariusf

I've editted your post to enclose your script in a "CODE" tag, and also to add tabbed formatting. I noticed that your brackets are currently not balanced. Your missing closing brackets in at least 2 places, so I suggest that you go through your code and fix these things.

If you're still having problems after you do that, then repost your new code in a CODE tag, and we'll talk another look.

- Miller

Dear Miller

Thank you for your suggestions, I really appreciate your help.

I have closed the brackets as suggested and included the 3rd abstraction of the image and text for the 3 column table. What happens now is that if I test the scipt with 1 image from an artist, the same image and text is used 3 times in 3 columns in the same row. In other words, my loops are not working as they should. The loops for each of the 3 columns in the row should somehow test to see if there is another image and abstract the image and text from the data line.

I include the code below again:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. # Stystem to build thumbnail image pages from data file
  4. # (Use htmlkop and htmlstert files for the start and end of each html file)
  5.  
  6. #Set the Parameters
  7.  
  8. $meesterdir = 'C:\F\Websites\Johan Smith NEW\artwork\thumbshtml'; #Directory where HTML is written to
  9. $datatabel = 'C:\F\Websites\Johan Smith NEW\artwork\datafile\datafile.txt'; #Directory were data file is
  10. $tumbsdir = 'C:\F\Websites\Johan Smith NEW\artwork\htmlcategory'; #Directory were thumbs page that is being created will be saved
  11. # print "$meesterdir\n";
  12.  
  13. #
  14.  
  15. #$htmlkop is the top part of HTML page
  16.  
  17. $htmlkopleer = 'C:\F\Websites\Johan Smith NEW\artwork\htmlkopthumbsnew.txt'; # File where htmlkop of the thumbs page is
  18. #sleep(1);
  19. # HTML kop
  20. $fx ='';
  21. open (LEER, $htmlkopleer) || die "Cannot open $htmlkopleer: $!\n";
  22. while (<LEER>) {$fx .=$_};
  23. close (LEER);
  24.  
  25. #print $fx;
  26. $htmlkop = $fx;
  27. #print "$htmlkop\n";
  28. sleep(1);
  29.  
  30. $htmlstertleer='C:\F\Websites\Johan Smith NEW\artwork\htmlstertthumbs.txt'; # File where htmlstert of the thumbs page is
  31.  
  32. # HTML stert
  33. $fx ='';
  34.  
  35. open (LEER, $htmlstertleer) || die "Cannot open $htmlstert: $!\n";
  36. while (<LEER>) {$fx .=$_};
  37. close (LEER);
  38.  
  39. #print $fx;
  40. $htmlstert = $fx;
  41. #print "$htmlstert\n";
  42. sleep(1);
  43.  
  44.  
  45. #
  46. # Now the data file is read to go further
  47.  
  48. #Each category is for a different artist for which we want to build a html page with all the thumnails and info of his works
  49.  
  50. %category = (
  51.     'adriaanhendrikboshoff' => 'Adriaan Hendrik Boshoff',
  52.     'johansmith'        => 'Johan Smith',
  53.     'alanainslie'         => 'Alan Ainslie',
  54. ); # end of list
  55.  
  56. #print $category; #Show category on screen to show what was done, this is just for testing the script.
  57. sleep(1);
  58.  
  59. #foreach $katelem (keys(%category)) {print "test $katelem $category{$katelem}\n";sleep(5)}
  60.  
  61. foreach $katelem (keys(%category)) {
  62.  
  63.     $catleernaam = $katelem;
  64.  
  65.     # print "$catleernaam\n"; #Show catleernaam on screen to indicate that step was done - only for testing
  66.     # sleep(1);
  67.  
  68.  
  69.     # sleep(1);
  70.  
  71.     #$category='';
  72.     $subcategory= '';
  73.  
  74.  
  75.  
  76.  
  77.     $thumbleer = $tumbsdir.'\\'.$catleernaam.'.html';
  78.     print "$thumbleer thumbleer\n\n";
  79.  
  80.     open (THUMBS,">$thumbleer") || die "cannot open thumb $thumbleer: $!\n";
  81.  
  82.     # Change <%cat_title%> with name of artist
  83.     #print "$katelem $category{$katelem} wie\n";
  84.  
  85.     $htmlkopb = $htmlkop;
  86.     $htmlkopb =~ s/<%cat_title%>/$category{$katelem}/;
  87.  
  88.     print THUMBS $htmlkopb;
  89.  
  90.  
  91.     # ==================================================
  92.     # From here the data line is read from data file and a test is done to see if it is still the same artist.
  93.     # ==================================================
  94.     open (LEER2, $datatabel) || die "cannot open data table $datatabel: $!\n";
  95.     while (<LEER2>){
  96.         $ding3=$_;
  97.  
  98.         chop($ding3); # Abstract one record line uit data table (file datafile.txt)
  99.         @velde = split(/%|%/,$ding3); # Split fields of each record at each %|%
  100.  
  101.         if ($velde[24] eq $katelem) {
  102.  
  103.  
  104.             # Start of cell 1 contents ========================
  105.             print THUMBS "<tr><td align=center><font size=1><a href=\"../htmldetail/$velde[0]/index.html\"\><img
  106. src=\"../htmldetail/$velde[0]/$velde[0]thumb.jpg\" align=center
  107. alt=\"Click for more\"></a></font><br><font color=#ffffff align=center><span style=\"font-size: 8pt;\">$velde[12]</strong><br><br>
  108. </font>
  109. </span>
  110. </td>"; #Cell 1 end
  111.             print THUMBS "";
  112.             sleep(1);
  113.                 } ;#end if;
  114.             }; # End while leer2
  115.  
  116. # -----------------------------------------------------------------
  117. # Cell 2 in the same row
  118.  
  119.             open (LEER2, $datatabel) || die "cannot open data table $datatabel: $!\n";
  120.             while (<LEER2>) {
  121.                 $ding3=$_;
  122.  
  123.                 chop($ding3); # Abstract one record line from data table (file datafile.txt)
  124.                 @velde = split(/%|%/,$ding3); # Split fields of each record at each %|%
  125.  
  126.                 if ($velde[24] eq $katelem) {
  127.  
  128.  
  129.                     # Start cell 2 contents ========================
  130.                     print THUMBS "<td align=center><font size=1><a href=\"../htmldetail/$velde[0]/index.html\"\><img
  131. src=\"../htmldetail/$velde[0]/$velde[0]thumb.jpg\" align=center
  132. alt=\"Click for more\"></a></font><br><font color=#ffffff align=center><span style=\"font-size: 8pt;\">$velde[12]</strong><br><br>
  133. </font>
  134. </span>
  135. </td>"; #Cell 2 end
  136.                     print THUMBS "";
  137.  
  138.                 } ;#end if;
  139.             }; # End while leer2
  140.  
  141. # -----------------------------------------------------------------
  142.  
  143.  
  144. # Cell 3 in the same row
  145.  
  146.             open (LEER2, $datatabel) || die "cannot open data table $datatabel: $!\n";
  147.             while (<LEER2>) {
  148.                 $ding3=$_;
  149.  
  150.                 chop($ding3); # Abstract one record line from data table (file datafile.txt)
  151.                 @velde = split(/%|%/,$ding3); # Split fields of each record at each %|%
  152.  
  153.                 if ($velde[24] eq $katelem) {
  154.  
  155.  
  156.                     # Start cell 3 contents ========================
  157.                     print THUMBS "<td align=center><font size=1><a href=\"../htmldetail/$velde[0]/index.html\"\><img
  158. src=\"../htmldetail/$velde[0]/$velde[0]thumb.jpg\" align=center
  159. alt=\"Click for more\"></a></font><br><font color=#ffffff align=center><span style=\"font-size: 8pt;\">$velde[12]</strong><br><br>
  160. </font>
  161. </span>
  162. </td>"; #Cell 2 end
  163.                     print THUMBS "";
  164.  
  165.                 } ;#end if;
  166.             }; # End while leer2
  167.  
  168. # -----------------------------------------------------------------
  169.  
  170.  
  171.  
  172.             close (LEER2);
  173.             print THUMBS "$htmlstert";
  174.             close (thumbs);
  175.         } # End foreach $katelem 
  176.  
  177.  
Apr 15 '07 #4
Maybe the word "the" in some lines should be "die", for example:

Expand|Select|Wrap|Line Numbers
  1. open (LEER, $htmlkopleer) || the "Cannot open $htmlkopleer \n";
and there are several more lines like that. You can also add "$!" to die lines to get the specific error returned by the operating system:

Expand|Select|Wrap|Line Numbers
  1. open (LEER, $htmlkopleer) || die "Cannot open $htmlkopleer: $!\n";

Thank you for the inputs, just to show you how a novice I really am: I have translated my comments in the script from my African language (Afrikaans) to English before the post. I did not recocnise that "die" is used in the perl scipt and thought that is should be "the" as translated from my language into English.

I have changed all that and include your recommended "$!" where required.

I have worked on the script and included it again in a message reply below.

Thanks so far.
Marius
Apr 15 '07 #5
KevinADC
4,059 Expert 2GB
another thing to note is you have this at the very end:

Expand|Select|Wrap|Line Numbers
  1.             close (LEER2);
  2.             print THUMBS "$htmlstert";
  3.             close (thumbs);
it will not prevent your script from running but "thumbs" (lowercase letters) has to be "THUMBS" (uppercase letters) as it is a reference to the filehandle THUMBS.

As far as your problem goes it's hard to say, that is a lot of code to try and look through and to try and understand whats going on. The continually opening the same file over and over is probably part of the problem if not the whole problem.

Expand|Select|Wrap|Line Numbers
  1.             open (LEER2, $datatabel) || die "cannot open data table $datatabel: $!\n";
  2.             while (<LEER2>) {
If you are going to print something into an html table you have to keep count of how many cells are getting printed (<td></td>) in order to know when to print a new row (</tr><tr>) and also to add empty table cells (<td></td>) to balance the rows and columns of the table. If all you ever intend is to print one row of three cells that should be easy. But if you have an unknown number or rows you have to keep track of when you come to the end of a row of cells.
Apr 15 '07 #6
another thing to note is you have this at the very end:

Expand|Select|Wrap|Line Numbers
  1.             close (LEER2);
  2.             print THUMBS "$htmlstert";
  3.             close (thumbs);
it will not prevent your script from running but "thumbs" (lowercase letters) has to be "THUMBS" (uppercase letters) as it is a reference to the filehandle THUMBS.

As far as your problem goes it's hard to say, that is a lot of code to try and look through and to try and understand whats going on. The continually opening the same file over and over is probably part of the problem if not the whole problem.

Expand|Select|Wrap|Line Numbers
  1.             open (LEER2, $datatabel) || die "cannot open data table $datatabel: $!\n";
  2.             while (<LEER2>) {
If you are going to print something into an html table you have to keep count of how many cells are getting printed (<td></td>) in order to know when to print a new row (</tr><tr>) and also to add empty table cells (<td></td>) to balance the rows and columns of the table. If all you ever intend is to print one row of three cells that should be easy. But if you have an unknown number or rows you have to keep track of when you come to the end of a row of cells.


Thanks for the inputs. I realise that I am out of my depth here. Is there anybody that can help me finalising the script for payment?
Alternatively I need to look at some free photo gallery type of scripts at http://gallery.menalto.com/ or http://coppermine-gallery.net/

Does some one have any suggestions?
Apr 17 '07 #7
KevinADC
4,059 Expert 2GB
I have no specific suggestion but I think it is a good idea you go with a pre-written image gallery script, there are tons and tons of them available. Which to use depends on your requirements. Copper-mine looks good.
Apr 17 '07 #8

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

Similar topics

0
by: Henk Verhoeven | last post by:
(Reply on this newsgroup to an email - reply by email did not work) Wolfman wrote: > > Hi, > I found your Email in the php Newsgroup. > I was looking for some way to resize some graphiks on my...
10
by: Don | last post by:
I want the server-side php script to return a browser page that is essentially a copy of the original client page that contained the <form> which referenced the php script in the first place....
2
by: Johan | last post by:
Hi, Where to find a php script to upload jpg files and make thumbnails of the jpg files ? Johan
10
by: Blue® | last post by:
I would like to call the content of content.htm (containing only HTML codes) into index.htm. This is usually done by renaming index.htm to index.shtml and use this tag: <!--#include...
14
by: mikeoley | last post by:
Why would this script below work on an html page: http://www.eg-designdev.com/aircylinders/test.htm But not a java page such as this: "http://www.eg-designdev.com/aircylinders/index3.jsp" Or...
2
by: Penguiniator | last post by:
I have a script that writes the body tag and adds a background image to its containing page. This page is displayed in an iframe inside a td tag of a table constructed with javascript. The table...
2
by: Muzzy | last post by:
Hi, I've used information on these newsgroups to build many pages. So I thought that now that I have my script working (something that I've been working on for about a week), I should post it so...
2
by: ranger7419 | last post by:
I'm trying to figure out why this script will work in IE 6 but not Firefox, and so I need someone here with a far better grasp on javascript to explain this. Basically, I have a page with several...
3
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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
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.