Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

add select list from data in another table

Quote Reply
add select list from data in another table
Basically, I have a custom table that I want to use as a relation for the Links table. The Links table has a "style_fk" field, which corresponds to "styleID" in the custom table. What I need to do is to generate a select list from the "styleID" and "styleName" fields from this table, so the user can select the proper style. (I realize I could have made the style column an ENUM and listed all the options there, but it seems like that might get messy since there are already 50+ choices, and I may want to add more columns to the custom table later anway.)

It would also be extremely helpful if this would work in the admin page as well.
Quote Reply
Re: [lostinva] add select list from data in another table In reply to
Well, I managed to get it working from the user side of things....

Code:
sub {
my $data = shift;
my $s_db = $DB->table('BeerStyle');
$s_db->select_options('ORDER BY StyleName');
my $sth = $s_db->select([qw/StyleID StyleName/]);

my $form = qq|<select name="style_fk">|;

while (my ($id, $style) = $sth->fetchrow_array()) {
if ($data !~ /^\d+$/) { $data = 1; } # 1 = unknown

my $selected;

if ($id == $data) {
$selected = 'selected';
}

$form .= qq|<option value="$id" $selected>$style</option>|;
}

$form .= qq|</select>|;

return $form;
}
Another thing I really need is for the user to have the option to create a new variety if it isn't already in the list. My guess is to have a "not listed" option and a text input field and to use a hook to insert it. Can someone tell me the hook for just after the add link process?
Quote Reply
Re: [lostinva] add select list from data in another table In reply to
Hi,

The hook for AFTER a link has been made? I think its add_link POST you want.

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!