CGI プログラム3

戻る

sub msc021 { my $self = shift; my(%t,$n,$n1); @{ $t{table} } = qw/our_ref makers/; # 各テーブルから最新データを抽出する for $n ( 0 .. $#{ $t{table} } ) { $t{table1} = $t{table}[$n]; @{ $t{ids} } = $self->dbh->selectrow_array("SELECT MAX(id) FROM $t{table1}"); @{ $t{items} } = $self->dbh->selectrow_array("SELECT * FROM $t{table1} where id = $t{ids}[0]"); $t{item1} = $t{items}[0]; for $n1 ( 1 .. $#{ $t{items} } ) { $t{item1} = $t{item1} . '==' . $t{items}[$n1]; } $t{list}{$t{table1}} = $t{item1}; } # Get CGI query object $t{q} = $self->query(); $t{template} = $self->load_tmpl('msc021.htm') || die "error loading tmpl"; for $n ( 0 .. $#{ $t{table} } ) { $t{table1} = $t{table}[$n]; $t{template}->param($t{table1} => $t{list}{$t{table1}}); } $t{template}->param(pro => "msc021.pl"); return $t{template}->output; } 1; -------------------------------------------------------------------------- sub mscsearch { my $self = shift; my(%t,$n,@loop); @{ $t{table} } = qw/our_ref makers/; # Get CGI query object $t{q} = $self->query(); $t{table_s} = $t{q}->param("table"); $t{word} = $t{q}->param("word1"); @loop = (); $t{NO} = 0; for $n ( 0 .. $#{ $t{table} } ) { $t{table1} = $t{table}[$n]; # 選択されたテーブル if ( $t{table_s} eq $t{table1} ) { $t{sth} = $self->dbh->prepare("SELECT * FROM $t{table1}"); $t{sth}->execute; while ( @{ $t{arr1} } = $t{sth}->fetchrow_array ) { $t{id1} = $t{arr1}[0]; $t{line1} = ''; for $n ( 1 .. $#{ $t{arr1} } ) { $t{line1} = $t{line1} . '==' . $t{arr1}[$n]; } if ( $t{line1} =~ /$t{word}/ ) { my $row_ref = (); # この初期化はとても重要! $$row_ref{id} = $t{id1}; $$row_ref{Line} = $t{line1}; push(@loop, $row_ref); $t{NO}++; } } $t{sth}->finish; } else { $t{list}{$t{table1}} = $t{q}->param($t{table1}); } } $t{html} = $t{q}->param("tmpl"); $t{html} = $t{html} . '.htm'; $t{template} = $self->load_tmpl("$t{html}") || die "error loading tmpl"; if ( $t{NO} == 0 ) { $t{list}{$t{table_s}} = $t{q}->param($t{table_s}); $t{template}->param(explain => "データはありません。再度検索してください。"); $t{template}->param($t{table_s} => $t{list}{$t{table_s}}); } else { $t{template}->param(explain => "1つを選択してから,クリックしてください"); $t{template}->param(THIS_LOOP => \@loop); } $t{template}->param(table => $t{table_s}); for $n ( 0 .. $#{ $t{table} } ) { $t{table1} = $t{table}[$n]; $t{template}->param($t{table1} => $t{list}{$t{table1}}); } $t{template}->param(pro => "mscsearch.pl"); return $t{template}->output; } 1; -------------------------------------------------------------------------- sub mscselect { my $self = shift; my(%t,$n,@loop); @{ $t{table} } = qw/our_ref makers/; # Get CGI query object $t{q} = $self->query(); $t{table_s} = $t{q}->param("table"); $t{id} = $t{q}->param("id"); # 各テーブルから for $n ( 0 .. $#{ $t{table} } ) { $t{table1} = $t{table}[$n]; if ( $t{table_s} eq $t{table1} && $t{id} != 0 ) { @{ $t{items} } = $self->dbh->selectrow_array("SELECT * FROM $t{table1} where id = $t{id}"); $t{item1} = $t{items}[0]; for $n1 ( 1 .. $#{ $t{items} } ) { $t{item1} = $t{item1} . '==' . $t{items}[$n1]; } $t{list}{$t{table1}} = $t{item1}; } else { $t{list}{$t{table1}} = $t{q}->param($t{table1}); } } $t{template} = $self->load_tmpl('msc021.htm') || die "error loading tmpl"; for $n ( 0 .. $#{ $t{table} } ) { $t{table1} = $t{table}[$n]; $t{template}->param($t{table1} => $t{list}{$t{table1}}); } $t{template}->param(pro => "mscselect.pl"); return $t{template}->output; } 1; -------------------------------------------------------------------------- sub mscsearch { my $self = shift; my(%t,$n,@loop); # Get CGI query object $t{q} = $self->query(); $t{word} = $t{q}->param("ourref1"); $t{table} = $t{q}->param("table"); $t{sth} = $self->dbh->prepare("SELECT * FROM $t{table}"); $t{sth}->execute; @loop = (); while ( @{ $t{arr1} } = $t{sth}->fetchrow_array ) { $t{id1} = $t{arr1}[0]; $t{line1} = ''; for $n ( 1 .. $#{ $t{arr1} } ) { $t{line1} = $t{line1} . '==' . $t{arr1}[$n]; } if ( $t{line1} =~ /$t{word}/ ) { my $row_ref = (); # この初期化はとても重要! $$row_ref{id} = $t{id1}; $$row_ref{Line} = $t{line1}; push(@loop, $row_ref); } } $t{sth}->finish; $t{html} = $t{q}->param("tmpl"); $t{html} = $t{html} . '.htm'; $t{template} = $self->load_tmpl("$t{html}") || die "error loading tmpl"; $t{template}->param(THIS_LOOP => \@loop); $t{template}->param(table => $t{table}); return $t{template}->output; } 1; -------------------------------------------------------------- tableにNULLが存在すれば==> Premature end of script headers
戻る