I have Table1 with the following format:
int(10) auto_increment unique id
varchar(255) state
varchar(255) city
varchar(255) location
text discription
Table2 looks like:
int(10) auto_increment unique comment_id
int(10) id
text comments
varchar(255) name
Table1 is list of locations with a discription. Table2 is a table of peoples comments on locations listed in Table1. Each comment in Table2 is linked to its corresponding location in Table1 by id. Table1.id = Table2.id, there can be unlimited comments in Table2 that correspond to one location in Table1, so it's a one to many relationship. How can I query an print my Table1 data with my Table2 comments appended.
Here is an overview of how I'm printing my Table1 data, I need to figure out how to modifiy it.
$dbh = DBI->connect("DBI:mysql:$database:$db_server", $user, $password +); { $statement = "SELECT id,state,city,discription FROM speedtrap WH +ERE state=$state"; } $sth = $dbh->prepare($statement) or die "Couldn't prepare the query: " +.$sth->errstr; $rv = $sth->execute or die "Couldn't execute query: ".$dbh->errstr; print <<EOF; <table border="1" align="center" width="100%"> <tr> <td width="1" height="1"> <p align="center">ID</p> </td> <td width="10%" height="1"> <p align="center">State</p> </td> <td width="20%" height="1"> <p align="center">City</p> </td> <td width="20%" height="1"> <p align="center">Location</p> </td> <td width="20%" height="1"> <p align="center">Discription</p> </td> </tr> EOF while (@row = $sth->fetchrow_array) { ($id,$state,$city,$Discription) = @row; print <<EOF; <tr> <td width="1" height="1>$id</td> <td width="10%" height="1">$state</td> <td width="20%" height="1">$city</td> <td width="20%" height="1">$location</td> <td width="70%" height="1">$discription</td> </tr> EOF } print "</table>"; } $rc = $sth->finish; $rc = $dbh->disconnect;
In reply to Perl database access by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |