> Hi All,
> 
> I am trying to fill a popup_menu with values retrieved from my database 
> and get the following error. Can't coerce array into hash at. As this is 
> the first time I'm doing this, could someone please assist in telling me 
> where I'm going wrong.

'at' what?  That would help.  Perl should be giving you a line number
that would help track down where the problem is. I couldn't see anything
on a quick glance but then usually I don't have to try and see where the
problem is, when Perl tells me.

> 
> $db="wotdb";
> $host="test";
> $port="436";
> $userid="wot";
> $passwd="wot";
> $connectionInfo="DBI:mysql:database=$db;$host:$port";
> $dbh = DBI->connect($connectionInfo,$userid,$passwd) || die("Could not
get 
> connected!");
> 
> my @ids = ();
> my %hostname = ();
> 
> $query = "SELECT * FROM hosts, ping_test where 
> hosts.hostname=ping_test.ping_hostname";

Why select * when you could just select what you need?

> $sth = $dbh->prepare($query);
> $sth->execute();
> my($hostname,$hostip,$hostport);
> 
Are the other variables already declared?

$sth->bind_columns(\$hostname,\$hostip,\$hostport,\$ping_date,\$ping_time,\$ping_hostname,
>                    
\$ping_hostip,\$ping_bytes,\$ping_icmp_seq,\$ping_timems,\$ping_tot_pack_trans,
>                    
\$ping_tot_pack_rec,\$ping_perc_pack_loss,\$ping_conn_status);
> 

Why are you binding the columns like this and then calling fetchrow_array?

> while(my($id,$hostname)=$sth->fetchrow_array)
> {

Personally to me it is easier to call fetchrow_hashref, then you don't
need to bind the columns or worry about a whole bunch of separate
variable names.  Which ends up looking something like,

while (my $row = $sth->fetchrow_hashref) {

    $hostname{ $row->{'id'} } = $row->{'hostname'};

>    push(@ids,$id);
>    $hostname{"$id"} = $hostname;

Why the two variables? You can use 'keys' with the hash to reproduce the
same list below.

perldoc -f keys

> }
> 
> print start_form,;
> print "<br>";
> print "<center><table border=0 cellpadding=3 cellspacing=1>";
> print "<tr>";
> print popup_menu('name'=>'hostname', 
> 'values'=>[EMAIL PROTECTED],'default'=>$hostname,'labels'=>\%hostname);
> print "</tr>";
> print "</table></center>";
> 

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to