You guys have been instrumental to getting my database running. Now I don't know how to append a second database to my first using perl. Here is a summary of my problem:

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.