Hi,

On Wed, 8 Aug 2001, David Draley wrote:

> I am writing a search script that will retrieve records from an MYSQL db.  I 
> have used an array to store the returned records, but I am having problems 
> pushing the array into a hash table.  So far, my search script only returns 
> the first record that matches the search criteria.
> 
> -------------------------------------
> my $sth = $dbh->prepare( "SELECT * FROM survey WHERE facil      = 
> '$species'" );
> 
> $sth->execute();
> 
> @rows = $sth->fetchrow_array();
> 
> <html>.....
> 
> @rows
> ....</html>

With fetchrow_array(), you are only grabbing one row at a time and need to
loop through like this:

my $sth = $dbh->prepare($sql) or db_err($DBI::errstr); 
$sth->execute or db_err($DBI::errstr);
while (@row = $sth->fetchrow_array()) {
        # do any html
        print @row;
        # do any html
        }

I set $, = "</TD><TD>" so that when my array is printed, each element
becomes a <TD> element:

$, = "</TD><TD>";

print<<EOP; 
<h3>All results by record</h3> 
<TABLE BORDER="1" WIDTH="80%">
EOP

while (@row = $sth->fetchrow_array()) {
        print "<TR><TD>";
        print @row;
        print qq!</TR>!;
        }

Hope this helps.

Lisa Wolfisch Nyman  <[EMAIL PROTECTED]>  IT Warrior Princess
"Life is too short to wear ugly underwear."
Get the facts at http://quickfacts.census.gov/





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to