Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: Unable to display data from hash arrayby benrwebb (Scribe) |
on Jun 14, 2004 at 16:12 UTC ( [id://366589]=note: print w/replies, xml ) | Need Help?? |
I would look at two things: First, if you are using HTML:Template, your TMPL_VAR tags don't look right... they should have a "name" as well: <TMPL_VAR name="fname"> Second, it looks like you are doing your assignments the hard way. If you return an AoH (Array of Hashes) from your call to DBI, you can assign that entire array to a loop within your template. For instance: I'll break down what just happened there. I'm using an object called Page (I use it for web pages in general), it has a method called dbselect that will query the database for me (the connection is set up elsewhere). $newst is an HTML::Template that I have genereated, so I call the param method of $newst with the output from dbselect assigned to the TMPL_LOOP news. It then fills in my news page with rows of news. Some day I'll update it to limit the number of stories, but I'm basically boring so I don't have that much news to display :-) Note the call to fetchall_arrayref({}) within dbselect. Read up on the documentation for DBI, in this format it returns AoH. The template that uses this looks like this: So you see, by using the AoH with a TMPL_LOOP, I was able to loop through everything with almost no code. Very easy once you understand it.
In Section
Seekers of Perl Wisdom
|
|