CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced:
Inserting MySQL row outputs into an array.

 



cuboidgraphix
User

Apr 25, 2009, 2:25 PM

Post #1 of 6 (2243 views)
Inserting MySQL row outputs into an array. Can't Post

Hi guys,
I am having a problem with a piece of code from a script I'm working on. The problem I'm having is that I want to query a MySQL database for a couple of rows (3 rows to be exact). Each row contains a phone number. The output rows (3 phone numbers) I then want to place into an array whereby system piece of code will read from the array and send an sms to the phone number.

Basically this is the flow of what I want to do.

1. MySQL query gets the three phone numbers.
2. The three phone numbers are inserted into an array. (this is the problem. I need them to be inserted into an array like this @number = ("$number[0]","$number[2]","$number[3]"); which will later be read by the system code.)

Can anybody help me? Below is the piece of code I have so far for getting the numbers..


Code
$query1 = "SELECT smart_number FROM $tablename1 WHERE active = '1'"; 
$sth1 = $dbh->prepare($query1);
$sth1->execute();
$sth1->bind_columns(undef, \$smart_number);

while($sth1->fetch()) {

# Here is where I want to insert the output into an array.

}



FishMonger
Veteran / Moderator

Apr 27, 2009, 9:03 AM

Post #2 of 6 (2184 views)
Re: [cuboidgraphix] Inserting MySQL row outputs into an array. [In reply to] Can't Post

Are you looking for fetchrow_array or fetchall_arrayref

http://search.cpan.org/~timb/DBI-1.607/DBI.pm#fetchall_arrayref

http://search.cpan.org/~timb/DBI-1.607/DBI.pm#fetchrow_array


Code
while( my ($smart_number) = $sth1->fetchrow_array) {  

push @phone_numbers, $smart_number;

}

or

Code
my $phone_numbers = $sth1->fetchall_arrayref;



cuboidgraphix
User

Apr 27, 2009, 10:50 AM

Post #3 of 6 (2180 views)
Re: [FishMonger] Inserting MySQL row outputs into an array. [In reply to] Can't Post

Thanks Fish... I'll give that a try and report back.

Thanks a Million!


cuboidgraphix
User

Apr 27, 2009, 3:16 PM

Post #4 of 6 (2170 views)
Re: [cuboidgraphix] Inserting MySQL row outputs into an array. [In reply to] Can't Post

It worked perfectly Fish... Thanks again man!!! You Rock!


KevinR
Veteran


Apr 27, 2009, 3:41 PM

Post #5 of 6 (2169 views)
Re: [cuboidgraphix] Inserting MySQL row outputs into an array. [In reply to] Can't Post


In Reply To
It worked perfectly Fish... Thanks again man!!! You Rock!


Only in a rocking chair! Wink
-------------------------------------------------


FishMonger
Veteran / Moderator

Apr 27, 2009, 4:40 PM

Post #6 of 6 (2166 views)
Re: [KevinR] Inserting MySQL row outputs into an array. [In reply to] Can't Post


In Reply To

In Reply To
It worked perfectly Fish... Thanks again man!!! You Rock!


Only in a rocking chair! Wink


And after a few cocktails. CrazyLaugh

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives