CGI プログラム7
戻る
# ourrefの自動生成
use strict;
use DBI;
use CGI qw/:standard/;
use HTML::Template;
my ( $dsn, $dbh, $sth, $no );
my ( %t, @fld, $sql, @rec, @rows, @rowsa, @rowsb );
my $template = HTML::Template->new(filename => 'mscenq1.htm');
my @loop = (); # initialize an array to hold your loop
$dsn = "DBI:mysql:host=localhost;database=cookbook";
$dbh = DBI->connect($dsn, "cbuser", "cbpass") or die "Cannot connect to server\n";
$dbh->do("SET NAMES utf8");
if(!$dbh){
print "SQL read ERROR!\n";
exit;
}
$t{ourref_maxid} = $dbh->selectrow_array("select max(id) from our_ref");
$t{ourref1} = $dbh->selectrow_array("select ourref from our_ref where id = $t{ourref_maxid}");
$dbh->disconnect;
# 今日の日付
($t{day},$t{month},$t{year}) = (localtime)[3,4,5];
$t{year} = substr($t{year},-1);
$t{month} = $t{month} + 1;
$t{month} = sprintf("%02d",$t{month});
$t{day} = sprintf("%02d",$t{day});
$t{ourref2} = $t{year} . $t{month} . $t{day} . '000';
$t{tmp1} = substr($t{ourref1},-3);
if ( $t{tmp1} eq '999' ) { # 最大は999
$t{ourref0} = $t{ourref1};
$t{ourref0_OK} = 'NG';
} elsif ( ($t{ourref1} - $t{ourref2}) >= 0 ) {
$t{ourref0} = $t{ourref1} + 1;
$t{ourref0_OK} = 'OK';
} else {
$t{ourref0} = $t{ourref2};
$t{ourref0_OK} = 'OK';
}
$template->param(ourref1 => $t{ourref1});
$template->param(ourref0 => $t{ourref0});
$template->param(ourref0_OK => $t{ourref0_OK});
# send the obligatory Content-Type and print the template output
print $template->output;
-------------------------------------------------------------------
---------------------------------------------------
use strict;
use CGI qw/:standard/;
use HTML::Template;
my (%t);
$t{q} = new CGI;
$t{name} = $t{q}->param("NAME");
$t{template} = HTML::Template->new(filename => 'mscenq2.htm');
$t{template}->param(name => $t{name});
# データ出力
print $t{template}->output;
---------------------------------------------------
name==>
-------------------------------------------------------------------
戻る