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;
戻る
呼图壁县| 眉山市| 库车县| 望奎县| 象山县| 定兴县| 吐鲁番市| 漳浦县| 砚山县| 视频| 安平县| 报价| 富川| 额敏县| 梓潼县| 自贡市| 黎川县| 左云县| 元谋县| 大悟县| 龙南县| 嫩江县| 台东市| 永川市| 桐柏县| 桐庐县| 阿拉尔市| 柘荣县| 峨山| 乌拉特后旗| 榕江县| 闽侯县| 凤山市| 娱乐| 山西省| 普陀区| 黄浦区| 辽宁省| 西乌珠穆沁旗| 景东| 读书|