in reply to Perl and DBI and CGI

I agree with blazar on both points, but try this & see if it sheds some light:
use Data::Dumper; my $ref = $dbh->selectall_arrayref("select * from users") || die $dbh->errstr; print Dumper($ref);



This is not a Signature...

Replies are listed 'Best First'.
Re^2: Perl and DBI and CGI
by sOKOle (Acolyte) on Jun 23, 2005 at 13:19 UTC
    Dear monkey_boy ! Thank you, Much better, but I have no idea how to improve formating and assign fields to the variables: $Name and $Email. In other words, how to make
    print "<font color=\"red\"> $Name"; print "<font color=\"ble\"> $Email";
    Regards, sOKOle
      Hi! Check if this is helps...
      $query = "SELECT Name, Email FROM users"; $sth = $dbh->prepare($query); $sth->execute(); while($Name,$Email) = $sth->fetchrow_array){ print "$Name, $Email";} $sth->finish(); $dbh->disconnect;
        Hi,

        The code is right, but using arrayref is more efficient/faster, consider it if you have a lot of data.

        Regards,
        ;-)
        Sorry, it does not help.
      You would be better specifying the column names in the sql, thus would be able to help you more, also dont forget to close your font tags , something like this:
      my $ref = $dbh->selectall_arrayref(" select name , email , age from users ") || die $dbh->errstr; foreach my $person (@{$ref}) { my ($name,$email,$age) = @{$person}; print "<font color=\"red\" > $name </font>"; print "<font color=\"blue\"> $email </font>"; };



      This is not a Signature...
        monkey_boy, your script works, but main problem re-occured When I have "Dr. John Bull" field it prints "Dr." only... could you solve ?
      Hint: use alternate delimiters, e.g. qq|"$whatever"|.