Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Perl and DBI and CGI

by monkey_boy (Priest)
on Jun 23, 2005 at 13:00 UTC ( #469373=note: print w/replies, xml ) Need Help??

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
      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 ?
      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;

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

        Sorry, it does not help.
      Hint: use alternate delimiters, e.g. qq|"$whatever"|.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://469373]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2021-10-27 16:18 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (94 votes). Check out past polls.