Desplegar los datos obtenidos de un fetchall_hashref()
Publicado: 2009-09-30 14:59 @666
Necesito saber cómo leo por medio de un foreach() los datos que obtengo de la consulta...
Tengo problemas al hacerlo por medio de
En el último foreach() es que tengo el problema. Decir $punto->{'imagen'} no sirve de nada.
Tengo problemas al hacerlo por medio de
Using perl Syntax Highlighting
my $sth = $self->dbh->prepare("SELECT id_localizacion, longitud, latitud, descripcion, tipo, propiedad, imagen FROM localizaciones WHERE tipo = ? AND propiedad = ?")
or die("Couldn't prepare statement: " . $self->dbh->errstr);
$sth->execute($datos->param('tipo'),$datos->param('propiedad')) or die("Couldn't execute statement: " . $sth->errstr);
my $puntos = $sth->fetchall_hashref('id_localizacion');
#my $puntos = $sth->fetchall_arrayref();
my $puntos2 = $sth->fetchall_arrayref;
$sth->finish;
$self->dbh->disconnect;
#return $t->{longitud};
#return "<pre>".Dumper($puntos);
#return Dumper($t->{longitud});
#return Dumper($puntos->{38}->{longitud});
if ($puntos) {
#foreach my $punto (keys %puntos){
foreach my $punto ( %$puntos ) {
$map->add_marker(
noformat => "1",
point => [$punto->{longitud}, $punto->{latitud} ],
html => "<img width=120 height=100 src='../clientes/uploads/$punto->{imagen}'><br><div style='width:120px;'>$punto->{descripcion} </div>",
icon => "$punto->{propiedad}"
);
}
}
or die("Couldn't prepare statement: " . $self->dbh->errstr);
$sth->execute($datos->param('tipo'),$datos->param('propiedad')) or die("Couldn't execute statement: " . $sth->errstr);
my $puntos = $sth->fetchall_hashref('id_localizacion');
#my $puntos = $sth->fetchall_arrayref();
my $puntos2 = $sth->fetchall_arrayref;
$sth->finish;
$self->dbh->disconnect;
#return $t->{longitud};
#return "<pre>".Dumper($puntos);
#return Dumper($t->{longitud});
#return Dumper($puntos->{38}->{longitud});
if ($puntos) {
#foreach my $punto (keys %puntos){
foreach my $punto ( %$puntos ) {
$map->add_marker(
noformat => "1",
point => [$punto->{longitud}, $punto->{latitud} ],
html => "<img width=120 height=100 src='../clientes/uploads/$punto->{imagen}'><br><div style='width:120px;'>$punto->{descripcion} </div>",
icon => "$punto->{propiedad}"
);
}
}
Coloreado en 0.003 segundos, usando GeSHi 1.0.8.4
En el último foreach() es que tengo el problema. Decir $punto->{'imagen'} no sirve de nada.