Gossamer Forum
Home : General : Perl Programming :

Code Question???

Quote Reply
Code Question???
Hi all...I'm new at perl, but trying...
I'm trying to get "@email" to hold all the email address from the mysql table...
but it only picks up , holds and prints the last email in the list....starting to really get to me....
I'm not sure how this works with mysql table....part of the code is below...
could anyone help on this one...thanks in adavance...Rob

$query = qq!
SELECT email
FROM $db_table
!;
$sth = $dbh->prepare ($query) or &cgierr("Unable to query database. Reason: $DBI::errstr. Query: $query");
$sth->execute or &cgierr("Unable to query database. Reason: $DBI::errstr. Query: $query");
@email = $sth->fetchrow_array;

foreach $name (@email)
{
print qq|<center><$font>$name </font> </center>
|;

}

Quote Reply
Re: Code Question??? In reply to
this is because the fetchrow_array method returns one record at a time.

try this:
Code:
while (my ($name) = $sth->fetchrow_array) {
print qq|<center><$font>$name </font> </center>|;
}
-g


s/(\d{2})/chr($1)/ge + print if $_ = '8284703280698276687967';
Quote Reply
Re: Code Question??? In reply to
Hi GClemmons..thanks for the input...your suggestion allows for a print out of all emails, but I need to store them in an array "@email" I can't figure out how to connect the @email values to the actual emails...thus:
(@emails) = $sth->fetchrow_array; thanks again...Rob

Quote Reply
Re: Code Question??? In reply to
Will this not work?

my @emails;

while (my ($name) = $sth->fetchrow_array) {
push(@emails, $name);
}


Installations:http://www.wiredon.net/gt/
Favicon:http://www.wiredon.net/favicon/

Quote Reply
Re: Code Question??? In reply to
OK GClemmons...thanks I got it...your input did it...much appreciate...thanks again...Rob

Quote Reply
Re: Code Question??? In reply to
Thanks Paul....I appreciate the assistance..works great..thanks again....Rob