mscs_engine.pl
if ( $t{word} ) {
# 讀name1
$t{sth} = $self->dbh->prepare("SELECT id,name FROM main_name1");
$t{sth}->execute;
while ( @rec = $t{sth}->fetchrow_array ) {
$t{name1}{$rec[0]} = $rec[1];
}
$t{sth}->finish;
# 讀maker1
$t{sth} = $self->dbh->prepare("SELECT id,name FROM main_maker1 where name is not NULL");
$t{sth}->execute;
while ( @rec = $t{sth}->fetchrow_array ) {
$t{maker1}{$rec[0]} = $rec[1];
}
$t{sth}->finish;
# 檢索main_type1
$t{sth} = $self->dbh->prepare("SELECT id,name,gname_id,maker_id FROM $t{table}");
$t{sth}->execute;
while ( @rec = $t{sth}->fetchrow_array ) {
$t{gname} = $t{name1}{$rec[2]};
$t{maker} = $t{maker1}{$rec[3]};
$t{line} = $rec[1] . ' ' . $t{gname} . ' ' . $t{maker};
$t{line} = lc($t{line});
if ( $t{line} =~ /$t{word}/ ) {
my $row_ref = (); # 非常重要!
$$row_ref{id} = $rec[0];
$$row_ref{Line} = $t{gname} . '' . $rec[1] . ' | ' . $t{maker};
$$row_ref{enq1_id} = $t{enq1_id};
$$row_ref{item} = $t{item};
push(@loop, $row_ref);
$t{NO}++;
}
}
$t{sth}->finish;
}
$t{template} = $self->load_tmpl("mscs_engine.htm") || die "error loading tmpl";
if ( $t{NO} == 0 ) {
$t{template}->param(explain => "沒有找到,請返回。");
} else {
$t{template}->param(explain => "請選一個(gè)");
$t{template}->param(THIS_LOOP => \@loop);
}
mysql> show columns from main_type1;
+----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(100) | YES | | NULL | |
| series | text | YES | | NULL | |
| gname_id | text | YES | | NULL | |
| maker_id | text | YES | | NULL | |
| GR | text | YES | | NULL | |
| DWG | text | YES | | NULL | |
| memo | text | YES | | NULL | |
+----------+--------------+------+-----+---------+----------------+
8 rows in set (0.13 sec)
mysql> show columns from main_name1;
+-------+-----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | char(100) | YES | | NULL | |
| memo | text | YES | | NULL | |
| cname | char(100) | YES | | NULL | |
| cmemo | text | YES | | NULL | |
| jname | char(100) | YES | | NULL | |
| jmemo | text | YES | | NULL | |
+-------+-----------+------+-----+---------+----------------+
mysql> show columns from main_maker1;
+-------+-----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-----------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | char(100) | YES | | NULL | |
| memo | text | YES | | NULL | |
| cname | char(100) | YES | | NULL | |
| cmemo | text | YES | | NULL | |
| jname | char(100) | YES | | NULL | |
| jmemo | text | YES | | NULL | |
+-------+-----------+------+-----+---------+----------------+
7 rows in set (0.22 sec)
返回
长宁县|
黄平县|
土默特左旗|
昔阳县|
章丘市|
沿河|
江陵县|
佛坪县|
体育|
新干县|
江川县|
黄大仙区|
德惠市|
绩溪县|
林口县|
乌兰察布市|
财经|
三台县|
永胜县|
静宁县|
阿坝县|
威信县|
兰西县|
红桥区|
惠州市|
东海县|
柞水县|
遂平县|
兰州市|
南皮县|
兴山县|
梧州市|
五台县|
米易县|
鹤庆县|
鸡泽县|
颍上县|
东台市|
桐乡市|
南岸区|
黄石市|
|