Gossamer Forum
Home : Products : DBMan SQL : Discussion :

auto write field

Quote Reply
auto write field
I am importing datafeeds and inporting them into DBSQL.

I have a field 'category' that can vary from day to day according to what data has been imported.

I want to generate a drop-down select box that is automatically populated with the data from the 'category' field- but I need to tell it to only display each entry in the field only once.

ie: I have 10 records all with the same category: 'Fashion' and 10 more with the category: 'Toys'
I want the select box to display the options 'Fashion' and 'Toys' once each.

This select box will be used within a search form.

Can this be done?

Thanks
Quote Reply
Re: [Alba] auto write field In reply to
Yes, it can be done by using the global template below:

sub {
my $tab = $DB->table('table_name');
$tab->select_options('GROUP BY category', 'ORDER BY category');
return { categories => $tab->select()->fetchall_hashref };
}

HTML code:

<%global_name%>
<select name="...">
<%loop categories%>
<option value="<%category%>"><%category%></option>
<%endloop%>
</select>

Hope that helps.

TheStone.

B.
Quote Reply
Re: [TheStone] auto write field In reply to
Thanks