Re: [htmltmpl] Select/option lists (how to generate)
Brought to you by:
samtregar
From: Mark A. F. <mar...@ea...> - 2005-01-10 19:57:14
|
From: Philip Tellis <phi...@gm...> > >I do it by pushing the selected evaluation right to the SQL: > >SELECT foo, bar, baz, IF(bar='myval', 'selected', '') AS selected FROM >... > >and then just throw it into an arrayref. That's the nifty SQL I mentioned seeing before. It was posted by Puneet.[1] ============================ SELECT val, text, (if then else to return "selected" or "") AS selected FROM table WHERE whatever... then in my template... <tmpl_loop occupations> <option value="<tmpl_var val>" <tmpl_var selected>> <tmpl_var text> </option> </tmpl_loop> ============================= But, the other nifty part was posted by Jason. He suggested using DBI's fetchall_arrayref to directly populate the template without putting the values in your own hash: ============================= $sth->execute(); $template->param( "OCCUPATION_LOOP" => $sth->fetchall_arrayref( {} ) ); ============================= [1] http://sourceforge.net/mailarchive/message.php?msg_id=8192715 [2] http://sourceforge.net/mailarchive/message.php?msg_id=8192723 Mark |