CGI プログラム4

戻る

sub mscsearch { my $self = shift; my(%t,$n,@loop); # Get CGI query object $t{q} = $self->query(); $t{tables} = $t{q}->param("tables"); @{ $t{table} } = split(/==/,$t{tables}); $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); # Get CGI query object $t{q} = $self->query(); $t{tables} = $t{q}->param("tables"); @{ $t{table} } = split(/==/,$t{tables}); $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{html} = $t{q}->param("tmpl"); $t{html} = $t{html} . '.htm'; $t{template} = $self->load_tmpl("$t{html}") || 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;
戻る