I use a script with 2 cases.
(leaving out the HTML for the background, etc., and assuming $dbi is the connection to your database, which has a table named QA consisting of 3 columns, Questions, Answers, and ID)

1st case:
my $statement = $dbh->prepare( "SELECT Questions, ID from QA;" ); $statement->execute(); my ($question, $id); $statement->bind_columns( \$question, \$id ); print "<ul>\n"; while ($statement->fetch) { print qq` <li><a href="[script_name]?case=2&id=$id">$question</li>` }
2nd case:
my $id = $cgi->param( 'id' ); my $statement = $dbh->prepare( qq`SELECT Questions, Answers from QA wh +ere ID = "$id";` ); $statement->execute(); my ($question, $answer); $statement->bind_columns( \$question, \$answer ); while ($statement->fetch) { print qq` <h2>$question</h2> <p>$answer</p>` }
The script calls itself, passing the ID of the question selected. This way both output pages will have the same format, regardless of future changes made, without having to update multiple files. Using fetch() also retrieves the information one line at a time, so your query won't give you a 10gig hash (as Ovid pointed out).
ID is a primary key auto-increment column used to identify each entry in the database. If you don't use that, you could also index Questions and do a select statement using something like WHERE Question like "[first 15 letters]%";, but this is the easiest way I've found. I'm sure there's a better way to do it, though, and I'm always open for suggestions/instruction

In reply to Re: Q & A by bnanaboy
in thread Q & A 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.