Gossamer Forum
Home : General : Databases and SQL :

quick DBI question

Quote Reply
quick DBI question
Hey there..

I'm trying to populate a pull-down list with 2 fields (firstname lastname) from a Mysql table:

mysql> describe main;
+----------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+-------+
| type | varchar(20) | YES | | NULL | |
| firstname | varchar(40) | YES | | NULL | |
| lastname | varchar(40) | YES | | NULL | |

This isn't working at all:

## html headers
print "Content-type: text/html\n\n";

## connect to the database
my $dbh = DBI->connect( "dbi:mysql:maindata", "", "" );
my $lastname = param("lastname");

## prepare a SQL statement for execution
$sth = $dbh->prepare( "SELECT firstname, lastname FROM main;");

## execute the statement in the database
$sth->execute();

my $table = $sth->fetchall_arrayref;
my($i, $j);

print qq {

<select name="nameselect" size="1">
<option selected></option>
for $i ( 0 .. $#{$table} ) {
for $j ( 0 .. $#{$table->[$i]} ) {
print "<option>$table->[$i][$j]\t</option>";
}
}
</select>
}

Can anyone help me on the syntax here?
Subject Author Views Date
Thread quick DBI question termid0g 12441 May 28, 2002, 8:35 AM
Post Re: [termid0g] quick DBI question
Wil 12224 May 28, 2002, 8:54 AM
Thread Re: [termid0g] quick DBI question
Paul 12298 May 28, 2002, 8:57 AM
Thread Re: [Paul] quick DBI question
termid0g 12292 May 28, 2002, 10:26 AM
Thread Re: [termid0g] quick DBI question
Paul 12307 May 28, 2002, 10:32 AM
Thread Re: [Paul] quick DBI question
termid0g 12308 May 28, 2002, 11:00 AM
Thread Re: [termid0g] quick DBI question
Paul 12344 May 28, 2002, 11:02 AM
Thread Re: [Paul] quick DBI question
termid0g 12335 May 28, 2002, 11:07 AM
Thread Re: [termid0g] quick DBI question
Wil 12245 May 28, 2002, 2:14 PM
Post Re: [Wil] quick DBI question
termid0g 12167 May 29, 2002, 8:52 AM
Thread Re: [Paul] quick DBI question
termid0g 12270 May 28, 2002, 11:14 AM
Thread Re: [termid0g] quick DBI question
Paul 12290 May 28, 2002, 11:45 AM
Post Re: [Paul] quick DBI question
termid0g 12217 May 28, 2002, 12:04 PM
Thread Re: [Paul] quick DBI question
termid0g 12227 May 29, 2002, 9:43 AM
Post Re: [termid0g] quick DBI question
Paul 12132 May 29, 2002, 10:29 AM