Perl Monk, Perl Meditation | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
...Retrieve data from MySQL via the DBI module -> display this data in HTML form -> make a form for someone to
input a row in the MySQL DB ...
...But I don't know quite where to go with the code I have come up with which is displayed here: I'm guessing that being told to use HTML::Template isn't exactly what you're looking for here, although it's very good advice.
If you're looking for advice on what to do to your code from
here, such that you can do the DBI lookup, show the table
entries and then offer an addition form then you might do
the following:
I'm sure you can edit your cgi code appropriately to fill in that loop. Abstracting the html around the loop into your template file allows you to later change the back-grounds of your table rows or data or their fonts or many other things without having to wade through your code again. Of course if you don't like HTML source, you might not realise the benefit of this today. Whether or not this duplicates loops depends on your code. If you do a query, then loop through all the results pushing the hashrefs you've fetched into an array and then give that to the template to loop through and display you've duplicated a loop. Perhaps you'd think it better to build your table inside your CGI code and then add that to a variable which you then display. HTML::Template purists will hate that idea, and they should, because you'd be perverting a very powerful and beautiful tool, but if it's the best solution you have, then use it. Then again, I'd encourage you not to be afraid of having two similar loops here (using TMPL_IF to replace possible null fields with   might also help). Jacinta In reply to Re: HTML::Template Form Usage
by jarich
|
|