Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Perl and DBI and CGI

by monkey_boy (Priest)
on Jun 23, 2005 at 13:00 UTC ( [id://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;
        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.
      Hint: use alternate delimiters, e.g. qq|"$whatever"|.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-19 00:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found