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: Beginner:
Help please. Problem re: returning results from DB query

 



Ben
Deleted

Apr 27, 2000, 9:21 AM

Post #1 of 3 (451 views)
Help please. Problem re: returning results from DB query Can't Post

If anyone can help, I would be most appreciative!

I am attempting to access a database using SQL query.

I have managed to get results returned using the "fetchrow_array" or "fetchrow_arrayref" functions. However, the returned values (say 6 rows..) seem to be looping repeatedly rather than printing the six rows and then stopping. What am I doing incorrectly?? Sample code below;

$stat = "SELECT ..... FROM....etc..
$sth = $dbh->prepare($stat);
$sth->execute($bind_var);

while (@row = $sth->fetchrow_array){
print "@row\n";
}


highland
Deleted

Apr 27, 2000, 3:30 PM

Post #2 of 3 (451 views)
Re: Help please. Problem re: returning results from DB query [In reply to] Can't Post

Hello,

In the above example, @row contains all the rows that meet the "$stat" array. So when you print "@row" inside a "fetchrow_array" it will print everything contained in @row for every match. There by "looping." I use somthing like this:

while(@row = $sth->fetchrow_array){
print "$row[0],$row[1],$row[2]";}
sth->finish;

I hope this helped,
John


Ben
Deleted

Apr 28, 2000, 10:25 PM

Post #3 of 3 (451 views)
Re: Help please. Problem re: returning results from DB query [In reply to] Can't Post

Thanks John..

I tried as you suggested but it gives me the same results (with only three elements of the array )... Any other possibilities??

Could I try using "fetch" instead of "fetchrow_array" ??

 
 


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

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