Try
fetchall_arrayref( {} ); instead of
fetchall_arrayref();, see if that works. Oh, and get rid of all your foreach stuff. Changing your fetchall_arrayref() call puts it in the format H::T is expecting for a TMPL_LOOP.
Oh - you probably will want to, at some point, change your database.
- You're storing a bunch of stuff in a comma-delimited list. That means you need a cross-reference table. Something like (in Oracle's DDL):
CREATE TABLE USER_BRANCH_XREF (
USER VARCHAR2(20) NOT NULL REFERENCES USERS(USERNAME)
,BRANCH NUMBER NOT NULL REFERENCES BRANCHES(ID)
,CONSTRAINT PRIMARY KEY (USER, BRANCH)
);
- Then, you have your users in one table and your branches in another. If a user has a connection to a branch, then the user's id and the branch's id are both put into the XREF table. So, if you now want to find all branches for a given user, do something like:
SELECT branches.id AS value
,branches.name AS branch
FROM users
,branches
,user_branch_xref
WHERE users.username = ?
AND user_branch_xref.user = users.username
AND user_branch_xref.branch = branches.id
- Then, you take the return value from fetchall_arrayref({}) from executing that statement (passing the $user in to the execute() call) and pass it directly to H::T.
Putting it all together, you would have:
my $sql = <<__END_SQL__;
SELECT branches.id AS value
,branches.name AS branch
FROM branches
,user_branch_xref
WHERE user_branch_xref.user = ?
AND user_branch_xref.branch = branches.id
__END_SQL__
my $sth = $dbh->prepare_cached( $sql ) or die $DBI::errstr;
$sth->execute( $user ) or die $DBI::errstr;
my $template = HTML::Template -> new(
filename => "../xm_dialogs/editmenu.tmpl",
);
$template->param(
branches => $sth->fetchall_arrayref( {} ),
);
------
We are the carpenters and bricklayers of the Information Age.
Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose
I shouldn't have to say this, but any code, unless otherwise stated, is untested
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.