生成兩個(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;
--------------------------------------------------------------
money_percent
money_percent
http://localhost/index.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");
--------------------------------------------------------------
戻る
高台县|
西乡县|
奉节县|
伊川县|
武功县|
华池县|
西藏|
华池县|
林州市|
新和县|
广东省|
益阳市|
闸北区|
涞水县|
青海省|
娱乐|
莆田市|
商水县|
塔城市|
紫阳县|
鄂尔多斯市|
德昌县|
寿宁县|
宜州市|
玉林市|
伊宁县|
定远县|
宜章县|
建水县|
顺义区|
广灵县|
徐州市|
连云港市|
宜宾市|
定远县|
小金县|
苗栗县|
时尚|
峨眉山市|
大厂|
麻江县|