生成兩個(gè)表的有關(guān)程序

戻る

#!C:/perl/bin/perl # show_money_percent.pl use strict; use DBI; use CGI qw/:standard/; use HTML::Template; my ( %t, @rec, @loop1, @loop2 ); $t{template} = HTML::Template->new(filename => 'money_percent.htm'); $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; } # money table $t{sth} = $t{dbh}->prepare("select * from money"); $t{sth}->execute; @loop1 = (); while (@rec = $t{sth}->fetchrow_array) { my %row = ( id => $rec[0], English => $rec[1], Chinese => $rec[2] ); push(@loop1, \%row); } $t{sth}->finish; # percent table $t{sth} = $t{dbh}->prepare("select * from percent"); $t{sth}->execute; @loop2 = (); while (@rec = $t{sth}->fetchrow_array) { my %row = ( id => $rec[0], Rate => $rec[1] ); push(@loop2, \%row); } $t{sth}->finish; $t{dbh}->disconnect; $t{template}->param(LOOP1 => \@loop1); $t{template}->param(LOOP2 => \@loop2); print $t{template}->output; 1; -------------------------------------------------------------- <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>money_percent</title> <head> <body bgcolor="#fcf5ca"> <h2>money_percent</h2> <a href="http://localhost/index.html">http://localhost/index.html</a><br> <hr> <center> <table> <tr bgcolor="white"><th>ID</th><th>English</th><th>Chinese</th></tr> <TMPL_LOOP NAME="LOOP1"> <tr bgcolor="white"> <td><TMPL_VAR NAME="id"></td> <td><TMPL_VAR NAME="English"></td> <td><TMPL_VAR NAME="Chinese"></td> </tr> </TMPL_LOOP> </table> </center> <hr> <center> <table> <tr bgcolor="white"><th>ID</th><th>Rate</th></tr> <TMPL_LOOP NAME="LOOP2"> <tr bgcolor="white"> <td><TMPL_VAR NAME="id"></td> <td><TMPL_VAR NAME="Rate"></td> </tr> </TMPL_LOOP> </table> </center> <hr> </body> </html> -------------------------------------------------------------- DROP TABLE IF EXISTS money; CREATE TABLE money ( id INT AUTO_INCREMENT, English char(30), Chinese char(30), PRIMARY KEY (id) ); INSERT INTO money (English,Chinese) VALUES("JPY","日元"); INSERT INTO money (English,Chinese) VALUES("USD","美元"); INSERT INTO money (English,Chinese) VALUES("EUR","歐元"); INSERT INTO money (English,Chinese) VALUES("GBP","英鎊"); INSERT INTO money (English,Chinese) VALUES("RMB","人民幣"); -------------------------------------------------------------- DROP TABLE IF EXISTS percent; CREATE TABLE percent ( id INT AUTO_INCREMENT, Rate varchar(10), PRIMARY KEY (id) ); INSERT INTO percent (Rate) VALUES("1.05"); INSERT INTO percent (Rate) VALUES("1.10"); INSERT INTO percent (Rate) VALUES("1.20"); INSERT INTO percent (Rate) VALUES("1.30"); INSERT INTO percent (Rate) VALUES("1.50"); INSERT INTO percent (Rate) VALUES("150"); INSERT INTO percent (Rate) VALUES("250"); --------------------------------------------------------------
戻る
浮梁县| 吐鲁番市| 晋江市| 平南县| 邵武市| 天津市| 宜兰市| 上栗县| 柳江县| 宝鸡市| 根河市| 沁水县| 托克逊县| 眉山市| 蒙山县| 虎林市| 保德县| 博客| 汉中市| 武鸣县| 福清市| 张北县| 乌鲁木齐县| 芮城县| 子洲县| 阜城县| 读书| 石门县| 宁蒗| 葫芦岛市| 乌兰县| 英超| 准格尔旗| 古浪县| 西平县| 汶上县| 保山市| 高青县| 博白县| 石嘴山市| 德庆县|