develooper Front page | perl.beginners | Postings from April 2002

Re: perl / database question

Thread Previous | Thread Next
Elaine -HFB- Ashton
April 2, 2002 10:15
Re: perl / database question
Message ID:
Johnson, Shaunn [] quoth:
*>Yes I am very new at this ... I was hoping I
*>could learn from some examples floating
*>around ... but I'm not sure where my results
*>should merge with the code (successfully).
*>The 'while' statement: I want to say 'while
*>reading from this list of tables, create
*>a scrolling window and populate it with
*>the results from the sql query from above'.
*>Are there any examples as to how to 
*>do this?

There are precious few out there as I went looking for a bare bones
example of something very similar for the CPAN Mirror page since I am not
a Web/CGI person and came up completely empty save for the examples from
the Perl DBI book

I use MySQL but I think the Postgres fretchrow is very similar to the
MySQL fetchrow so you'll have something like:

my $sth = $dbh->prepare( "
            SELECT name,summary
            FROM list
            ORDER by name
          " );

while ( my ( $name, $summary ) = $sth->fetchrow_array ) {
    print <<EOF;

similarly for a select list/pull-down menu list

    my $sth = $dbh->prepare( "
                SELECT DISTINCT category
                FROM list
                ORDER by category
              " );
    my %categories;

    while ( my ( $category ) = $sth->fetchrow_array ) {
@categories{split(' ', $category)} = ();
    for my $category (sort keys %categories) {

<OPTION  VALUE="$category">$category</OPTION>
<P><INPUT TYPE="submit" VALUE="Category"></P>

where you make the query then dump out the contents in a while loop with a
HERE doc. Your mileage may vary, but that's basically it :)


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About