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

Returning ID as value in dropdown

Quote Reply
Returning ID as value in dropdown
Heya all,

I use the global below to generate a dropdown of links from a LinsSQL db. The way this is written it returns the Title as the "value" of the dropdown. I would like to display the Title field in the dropdown but actually return the ID of the link as the value.

I want this line:
$output .= "<option selected>$title";

changed to something like:
$output .= "<option selected value=$ID>$title";

Any suggestions on how I should tweak the Global?

Code:
sub {
my $db = GT::SQL->new('/path/to/other/linksSQL/admin/defs');
my $tbl = $db->table('Links');
my $selected = GT::Template->tags->{event_dz};
$tbl->select_options('ORDER BY Title');
my $sth = $tbl->select(['Title']);
my $output = '<select name="event_dz" size="1"><option></option>';
while (my ($title) = $sth->fetchrow_array) {
$title = $IN->html_escape($title);
if ($title eq $selected) {
$output .= "<option selected>$title";
}
else {
$output .= "<option>$title";
}
}
$output .= "</select>";
return \$output;
}

Safe swoops
Sangiro
Quote Reply
Re: [sangiro] Returning ID as value in dropdown In reply to
Like so? Smile

Code:
sub {
my $db = GT::SQL->new('/path/to/other/linksSQL/admin/defs');
my $tbl = $db->table('Links');
my $selected = GT::Template->tags->{event_dz};
$tbl->select_options('ORDER BY Title');
my $sth = $tbl->select(['Title','ID']);
my $output = '<select name="event_dz" size="1"><option></option>';
while (my ($title,$id) = $sth->fetchrow_array) {
$title = $IN->html_escape($title);
if ($title eq $selected) {
$output .= "<option value=$id selected>$title";
}
else {
$output .= "<option value=$id>$title";
}
}
$output .= "</select>";
return \$output;
}

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!
Quote Reply
Re: [Andy] Returning ID as value in dropdown In reply to
Andy,

That worked great thank you. Smile One more thing... how can I now use this ID to retieve all the info (or just the title) of a specific link? In other words, if I've saved a value (ID) above I would somehow like to use a global with a tag like <%global name($ID)%> to return the title of that link.

Safe swoops
Sangiro
Quote Reply
Re: [sangiro] Returning ID as value in dropdown In reply to
No worries.

Quote:
One more thing... how can I now use this ID to retieve all the info (or just the title) of a specific link? In other words, if I've saved a value (ID) above I would somehow like to use a global with a tag like <%global name($ID)%> to return the title of that link.

Pretty simple really;

Code:
sub {

my $ID = $_[0];
my $field = $_[1];
my $table= $_[2];

my $val = $DB->table($table)->select( [$field], { ID => $ID })->fetchrow;
return $val;

}

Call with;

<%global_name($ID,'FieldNme','TableName')%>

Hope that helps.

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!

Last edited by:

Andy: Oct 21, 2004, 8:54 AM
Quote Reply
Re: [Andy] Returning ID as value in dropdown In reply to
Beautiful. Thank you sir. That does the job! Smile

Safe swoops
Sangiro