CGI プログラム5
戻る
#!C:/perl/bin/perl
# show_parts1
use strict;
use DBI;
use CGI qw/:standard/;
use HTML::Template;
my ( %t, $n, @loop, @rec );
$t{template} = HTML::Template->new(filename => 'parts1.htm');
@loop = (); # initialize an array to hold your loop
$t{dsn} = "DBI:mysql:host=localhost;database=cookbook";
$t{dbh} = DBI->connect($t{dsn}, "cbuser", "cbpass") or die "Cannot connect to server\n";
$t{dbh}->do("SET NAMES utf8");
if(!$t{dbh}){
print "SQL read ERROR!\n";
exit;
}
$t{sth} = $t{dbh}->prepare("select id, name,code,engine,DWG,memo from parts1");
$t{sth}->execute;
$t{NO} = -1;
while (@rec = $t{sth}->fetchrow_array) {
$t{NO}++;
@{ $t{list}[$t{NO}] } = @rec;
}
$t{sth}->finish;
for $n ( 0 .. $#{ $t{list} } ) {
# エンジン番號(hào)からエンジン名を抽出
$t{engine_name} = $t{dbh}->selectrow_array("select name from main_type1 where id = $t{list}[$n][3]");
my %row = (
id => $t{list}[$n][0],
name => $t{list}[$n][1],
code => $t{list}[$n][2],
engine => $t{engine_name},
DWG => $t{list}[$n][4],
memo => $t{list}[$n][5]
);
# put this row into the loop by reference
push(@loop, \%row);
}
$t{dbh}->disconnect;
$t{template}->param(THIS_LOOP => \@loop);
# send the obligatory Content-Type and print the template output
print $t{template}->output;
1;
戻る
大埔区|
北海市|
隆昌县|
新昌县|
许昌县|
新竹市|
永新县|
凤翔县|
通许县|
宁阳县|
安顺市|
富蕴县|
威信县|
高台县|
郎溪县|
台北县|
乌拉特前旗|
顺义区|
灵武市|
石城县|
遂川县|
绩溪县|
西华县|
望奎县|
民勤县|
静乐县|
榆林市|
鄂伦春自治旗|
伊春市|
永安市|
中宁县|
安义县|
同江市|
佳木斯市|
长寿区|
武城县|
抚远县|
阿坝|
波密县|
禹城市|
山丹县|