Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create dynamic HTML 1

Status
Not open for further replies.
Jun 20, 2003
40
GB
How do I get the real value and not the arrayref into my menu list from this source data?

my $cur = $dbh->prepare("SELECT Device_Name FROM tbl_admin_systems");
$cur->execute();

my $menu = $cur->fetchall_arrayref();

my $q = CGI->new;

print $q->header;
print $q->start_html(-title=>'Menu');
print $q->popup_menu(-name=>'This is a menu', -values=>$menu);
print $q->end_html;
$cur->finish();

The column contains "SVR1, SVR2, SVR3, SVR4".

Thanks for your help.

Cheers
 
Code:
print $q->popup_menu(-name=>'This is a menu', -values=>@{$menu});

[tt]@{$menu}[/tt] is the array dereferenced from the [tt]$menu[/tt] array ref.
 
Thanks for that, rosenk. However I'm only getting one menu item in my list where as I was getting the entire column of data (array's anyway).
 
I believe you have to to something like this:

$values[0]
$values[1]
$values[2]

etc.

you'll need a "for" or "while" loop to terminate the process when it gets to the end of the array.

There's always a better way. The fun is trying to find it!
 
Ah, right. [tt]fetchall_arrayref[/tt] returns a reference to an array of array references. Also, you're supposed to pass an arrayref for -values. Try this:

Code:
print $q->popup_menu(-name=>'This is a menu', -values=> [map { $_->[0] } @{$menu}]);

That's assuming that you want the first element of each row, of course.
 
Thnaks rosenk, does the I need. I must spent some time going over array's again, one day I'll work it out.

Cheers for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top