=1 order by janru_id asc";
$res = @mysql_query($sql);
$max[0]=mysql_fetch_array($res);
//テーブルの中身
$sql_d = "select janru_name from display_janru where janru_id != 99 and janru_id>=1 order by janru_id asc";
$res_d = @mysql_query($sql_d);
for($i=1;$row=mysql_fetch_array($res_d);$i++){
$janru_d[$i]=$row['janru_name'];
}
mysql_free_result($res);
$close = @mysql_close($con);
if(!$close){
unset($con,$sql,$res,$max,$db_select);
die();
}
unset($con,$sql,$res,$db_select,$i);
//追加
if($_POST['flag']==1 && $_POST['janru_name']!=null){
$con = @mysql_connect("localhost","event","L523GpA");
if(!$con){
unset($con);
die();
}
$db_select = @mysql_select_db("eventdb");
mysql_query("set names utf8");
//バックアップ削除
@mysql_query("delete from display_janru where janru_id=99");
//レコードの追加
@mysql_query("insert into display_janru (janru_id,janru_name) values (".($max[0]['cnt']+1).",'".htmlspecialchars($_POST['janru_name'])."')");
//バックアップ
@mysql_query("insert into display_janru (janru_id,janru_name) values (99,'".htmlspecialchars($_POST['janru_name'])."')");
$close = @mysql_close($con);
if(!$close){
unset($con,$sql,$res,$max,$db_select);
die();
}
unset($con,$sql,$res,$db_select);
$back_ch=1;
}
//削除
if($_POST['flag']==2 && $_POST['janru_id2']!=null && $_POST['janru_id2']>=1){
$con = @mysql_connect("localhost","event","L523GpA");
if(!$con){
unset($con);
die();
}
$db_select = @mysql_select_db("eventdb");
mysql_query("set names utf8");
$sql = "select count(janru_id) as cnt from display_master where janru_id=".$_POST['janru_id2']." and kanko_id !=99 ";
$res = @mysql_query($sql);
$data_ch[0]=mysql_fetch_array($res);
if($data_ch[0]['cnt']==0){
//バックアップ削除
@mysql_query("delete from display_janru where janru_id=99");
//レコードの削除
$data1=@mysql_query("delete from display_janru where janru_id=".$_POST['janru_id2']." ");
//バックアップ
$bac1=@mysql_query("insert into display_janru (janru_id,janru_name) values (99,'".$janru_d[$_POST['janru_id2']]."')");
if($_POST['janru_id2']<$max[0]['cnt']){
for($i=$_POST['janru_id2'];$i<$max[0]['cnt'];$i++){
$data2=@mysql_query("update display_janru set janru_id=".$i." where janru_id=".($i+1)." ");
$data3=@mysql_query("update display_master set janru_id=".(99-$i)." where janru_id=".($i+1)."");
}
for($i=$_POST['janru_id2'];$i<$max[0]['cnt'];$i++){
$data4=@mysql_query("update display_master set janru_id=".$i." where janru_id=".(99-$i)."");
}
}
if($data1 === true && $data2 === true && $data3 === true && $data4 === true && $bac1 === true){
//コミット
$Query = "commit";
mysql_query($Query);
}else{
//ロールバック
$Query = "rollback";
mysql_query($Query);
}
$back_ch=1;
}else{
echo "
選択したジャンルを使用したデータがあるため、削除できません。";
$back_ch=0;
}
$close = @mysql_close($con);
if(!$close){
unset($con,$sql,$res,$max,$db_select);
die();
}
unset($con,$sql,$res,$db_select,$data1,$data2,$data3,$bac1);
}
//書き換え
if($_POST['flag']==3 && $_POST['janru_id2']!=null && $_POST['janru_id2']>=1 && $_POST['janru_name']!=null){
$con = @mysql_connect("localhost","event","L523GpA");
if(!$con){
unset($con);
die();
}
$db_select = @mysql_select_db("eventdb");
mysql_query("set names utf8");
//バックアップ削除
@mysql_query("delete from display_janru where janru_id=99");
//レコードの書き換え
$data3=@mysql_query("update display_janru set janru_name='".htmlspecialchars($_POST['janru_name'])."' where janru_id=".$_POST['janru_id2']." ");
//バックアップ
$bac2=@mysql_query("insert into display_janru (janru_id,janru_name) values (99,'".$janru_d[$_POST['janru_id2']]."')");
if($data3 === true && $bac2 === true){
//コミット
$Query = "commit";
mysql_query($Query);
}else{
//ロールバック
$Query = "rollback";
mysql_query($Query);
}
$close = @mysql_close($con);
if(!$close){
unset($con,$sql,$res,$max,$db_select);
die();
}
unset($con,$sql,$res,$db_select,$data3,$bac2);
$back_ch=1;
}
//挿入
if($_POST['flag']==4 && $_POST['janru_id2']!=null && $_POST['janru_id2']>=1 && $_POST['janru_name']!=null){
$con = @mysql_connect("localhost","event","L523GpA");
if(!$con){
unset($con);
die();
}
$db_select = @mysql_select_db("eventdb");
mysql_query("set names utf8");
//バックアップ削除
@mysql_query("delete from display_janru where janru_id=99");
//レコードの書き換え
$data4=@mysql_query("update display_janru set janru_name='".htmlspecialchars($_POST['janru_name'])."' where janru_id=".$_POST['janru_id2']." ");
for($i=$_POST['janru_id2']+1;$i<=$max[0]['cnt'];$i++){
$data5=@mysql_query("update display_janru set janru_name='".$janru_d[$i-1]."' where janru_id=".$i." ");
$data6=@mysql_query("update display_master set janru_id=".(99-$i)." where janru_id=".($i-1)."");
}
$data7=@mysql_query("insert into display_janru (janru_id,janru_name) values (".$i.",'".$janru_d[($i-1)]."')");
$data8=@mysql_query("update display_master set janru_id=".(99-$i)." where janru_id=".($i-1)."");
for($i=$_POST['janru_id2']+1;$i<=$max[0]['cnt'];$i++){
$data9=@mysql_query("update display_master set janru_id=".$i." where janru_id=".(99-$i)."");
}
$data10=@mysql_query("update display_master set janru_id=".$i." where janru_id=".(99-$i)."");
//バックアップ
$bac3=@mysql_query("insert into display_janru (janru_id,janru_name) values (99,'".$janru_d[$_POST['janru_id2']]."')");
if($data4 === true && $data5 === true && $data6 === true && $data7 === true && $data8 === true && $data9 === true && $data10 === true && $bac3 === true){
//コミット
$Query = "commit";
mysql_query($Query);
}else{
//ロールバック
$Query = "rollback";
mysql_query($Query);
}
$close = @mysql_close($con);
if(!$close){
unset($con,$sql,$res,$max,$db_select);
die();
}
unset($con,$sql,$res,$db_select,$data3,$bac2);
$back_ch=1;
}
//更新後の表示
print("ジャンル編集
登録ジャンル一覧
");
$con = @mysql_connect("localhost","event","L523GpA");
if(!$con){
unset($con);
die();
}
$db_select = @mysql_select_db("eventdb");
mysql_query("set names utf8");
//レコードのカウント
$sql = "select count(janru_id) as cnt from display_janru where janru_id != 99 and janru_id>=1 order by janru_id asc";
$res = @mysql_query($sql);
$max[0]=mysql_fetch_array($res);
//テーブルの中身
$sql_d = "select janru_name from display_janru where janru_id != 99 and janru_id>=1 order by janru_id asc";
$res_d = @mysql_query($sql_d);
print("