perleager has asked for the wisdom of the Perl Monks concerning the following question:
print <<EOF; Company Info:<br> <table cellpadding="2" cellspacing="0" border="0" width="100%"> <tr> <td>ID</td> <td>Name</td> <td>Company</td> <td>Country</td> <td>File</td> <td>Summary</td> <td>Date Submitted</td> </tr> EOF #retrieve business plans $ci_blah = "mypassword"; use DBI; $dbh_m = DBI->connect('DBI:mysql:companies','myusername',$ci_bla +h) or die "Couldn't connect to database: " . DBI->errstr; $sql_m = "SELECT id,firstname,lastname,country,file_name,summ +ary,date FROM companies_db"; $sth_m = $dbh_m->prepare($sql_m) or die "preparing: ",$dbh_m- +>errstr; $sth_m->execute or die "executing: ", $dbh_m->errstr; $results = $sth_m->fetchrow_hashref; print " <tr>"; print " <td>$results->{'id'}</td>"; print " <td>$results->{'firstname'} $results{'lastname'}</td>"; print " <td>$results->{'company'}</td>"; print " <td>$results->{'country'}</td>"; print " <td>$results->{'file_name'}</td>"; print " <td>$results->{'summary'}</td>"; print " <td>$results->{'date'}</td>"; print " </tr>"; while (@data = $sth_m->fetchrow_array()) # keep fetching until # there's nothing left { print " <tr>"; print " <td>$data[0]</td>"; print " <td>$data[1] $data[2]</td>"; print " <td>$data[3]</td>"; print " <td>$data[4]</td>"; print " <td>$data[5]</td>"; print " <td>$data[6]</td>"; print " <td>$data[7]</td>"; print " </tr>"; } $sth_m->finish; $dbh_m->disconnect; print "</table>";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Fetchrow_hash/array question with DBI/Perl
by dbwiz (Curate) on Mar 20, 2004 at 21:15 UTC | |
by perleager (Pilgrim) on Mar 20, 2004 at 21:56 UTC | |
|
Re: Fetchrow_hash/array question with DBI/Perl
by etcshadow (Priest) on Mar 20, 2004 at 21:09 UTC | |
|
Re: Fetchrow_hash/array question with DBI/Perl
by jeffa (Bishop) on Mar 21, 2004 at 17:32 UTC | |
|
Re: Fetchrow_hash/array question with DBI/Perl
by pbeckingham (Parson) on Mar 21, 2004 at 01:30 UTC |