in reply to AoH refs for setting HTML::Template loops

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.

  1. 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) );
  2. 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
  3. 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