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?
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?