mscdelete2

戻る

#!C:/perl/bin/perl ###################################### # mscdelete2.pl ###################################### use strict; use DBI; use CGI qw/:standard/; use HTML::Template; my ( %t, @rec, @loop, $n, $p_ref ); $t{q} = new CGI; $t{enq1_id} = $t{q}->param("enq1_id"); $t{id2} = $t{q}->param("id2"); $t{NO1} = $t{q}->param("NO1"); # 主機タイプの順番 $t{template} = HTML::Template->new(filename => 'mscdelete2.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; } $$p_ref{NO1} = $t{NO1}; $$p_ref{id2} = $t{id2}; $$p_ref{list2} = $t{dbh}->selectrow_array("select partsid from enq1 where id = $t{enq1_id}"); ($p_ref) = parts2($p_ref); $t{sql} = 'UPDATE enq1 set ' . 'partsid' . ' = "'; $t{sql} .= $$p_ref{list2new} . '" where id = '; $t{sql} .= $t{enq1_id}; $t{DO} = $t{dbh}->do($t{sql}); $t{dbh}->disconnect; $t{template}->param(enq1_id => $t{enq1_id}); $t{template}->param(id2 => $t{id2}); $t{template}->param(NO1 => $t{NO1}); $t{template}->param(DO => $t{DO}); $t{template}->param(sql => $t{sql}); # send the obligatory Content-Type and print the template output print $t{template}->output; sub parts2 { #パーツ削除処理 my($p_ref) = @_; my(%t,$n,$n1); $t{list2} = $$p_ref{list2}; $t{NO1} = $$p_ref{NO1}; $t{id2} = $$p_ref{id2}; @{ $t{list2s} } = split(/==/,$t{list2}); @{ $t{list2snew} } = (); @{ $t{list2ssnew} } = (); for $n ( 0 .. $#{ $t{list2s} }) { $t{NO2} = $n + 1; if ( $t{NO1} == $t{NO2} ) { @{ $t{list2ss} } = split(/=/,$t{list2s}[$n]); for $n1 ( 0 .. $#{ $t{list2ss} } ) { next if ( $t{id2} == $t{list2ss}[$n1] ); push(@{ $t{list2ssnew} },$t{list2ss}[$n1]); } $t{list2new} = join('=',@{ $t{list2ssnew} }); push(@{ $t{list2snew} },$t{list2new}); } else { push(@{ $t{list2snew} },$t{list2s}[$n]); } } $$p_ref{list2new} = join('==',@{ $t{list2snew} }); return($p_ref); } 1; ------------------------------------------------------------------------------- <html> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <head><title>mscdelete</title> <head> <body bgcolor="#fcf5ca"> <h2>mscdelete</h2> <a href="http://localhost/scripts/mscenq1_p.pl">http://localhost/scripts/mscenq1_p.pl</a><br> <hr> ENQ_ID==><TMPL_VAR NAME="enq1_id"><br> id2==><TMPL_VAR NAME="id2"><br> NO1==><TMPL_VAR NAME="NO1"><br> <hr> DO==><TMPL_VAR NAME="DO"><br> sql==><TMPL_VAR NAME="sql"> </body> </html>
戻る