On Apr 10, 2005, at 11:30 AM, Eko Budiharto wrote:
Hi,
I would like to ask about how to retrieve a value from mysql and use it later. What I mean is like this
This is really a perl question, not mysql. my is a scoping operator. Variables declared with my disappear when they go out of scope.
my $ref = $sth->fetchall_arrayref();
foreach my $row (@$ref) {
my ( $passengerIndex, $passengerName, $passengerEmailAddress, $passengerLoginPassword ) = @$row;
my $new = $passengerIndex;
$new belongs to the foreach loop.
}
$new disappears here, as it has gone out of scope.
...<other scripts and html header>
print $new;
but it does not work.
so far, when I want to use it, I always do this
my $ref = $sth->fetchall_arrayref();
foreach my $row (@$ref) {
my ( $passengerIndex, $passengerName, $passengerEmailAddress, $passengerLoginPassword ) = @$row;
my $new = $passengerIndex;
...<other scripts and html header>
print $new;
}
You have to create $new so it is in the desired scope. You need something like
my $new;
my $ref = $sth->fetchall_arrayref();
foreach my $row (@$ref) {
my ( $passengerIndex, $passengerName, $passengerEmailAddress, $passengerLoginPassword ) = @$row;
$new = $passengerIndex;
}
...<other scripts and html header>
print $new;
Michael
-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]