List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:July 19 1999 11:19pm
Subject:Re: Question on Select using Perl..
View as plain text  
At 6:05 PM -0500 7/19/99, Robert (IMI) wrote:
>Question on SELECT statement..
>
>I use this code to return a row of data that matches a search..
>
> my $query = "SELECT
>  banner_gif,
>  banner_url,
>  banner_comment
> FROM banner WHERE (
>  username like '$FORM{'username'}')";
>
> my $sth = $dbh->prepare($query);
> my $rc = $sth->execute;
> @banner_info = $sth->fetchrow_array;
> $sth->finish;
>
>This is the banner table layout that I have..
>
>mysql> describe banner;
>+----------------+--------------+------+-----+---------+-------+
>| Field          | Type         | Null | Key | Default | Extra |
>+----------------+--------------+------+-----+---------+-------+
>| username       | varchar(25)  |      | MUL |         |       |
>| banner_gif     | varchar(100) | YES  |     | NULL    |       |
>| banner_url     | varchar(100) | YES  |     | NULL    |       |
>| banner_comment | varchar(20)  | YES  |     | NULL    |       |
>+----------------+--------------+------+-----+---------+-------+
>
>This works great with return one row.. but what I need is to return
>several rows into a variable that I can parse out and work with..
>
>I am sure it has something to do with this line
>
>@banner_info = $sth->fetchrow_array;
>
>I am programming in perl by the way..  When I do the SELECT statement from
>a mysql prompt I get the results that I would expect.. if I have three
>records that match the username all three are returned.. but with my code
>above I am only seeing the first record.. how would I change my code to be
>able to capture more than one record.. ?


The array that fetchrow_array returns is an array containing column values
for the current row, not an array containing the contents of each row.  Put
your method invocation in a loop and you'll be all right:

while (@banner_info = $sth->fetchrow_array)
{
}

--
Paul DuBois, paul@stripped
Thread
Question on Select using Perl..IMI)20 Jul
  • Re: Question on Select using Perl..Johan Isacsson20 Jul
  • Re: Question on Select using Perl..Paul DuBois20 Jul
    • Re: Question on Select using Perl..IMI)20 Jul
  • Renaming table fields.Thomas Barrett29 Jan
    • Re: Renaming table fields.Jeff Urban29 Jan
    • Re: Renaming table fields.Paul DuBois29 Jan