一覧にボタンを追加して、データのメンテナンスを行う

  VIEWの変更



  
データが無い場合の画面制御の為、ヒアドキュメントを使わない

<center>
<h1>学生リスト</h1>
<table  cellpadding=5>
	<th>コード</th>
	<th width=200>名前</th>
	<th>学年</th>
	<th width=100>誕生日</th>
	<th width=100>電話番号</th>	
	<!-- row:1 -->
	<tr>
		<td bgcolor=white>
		<? if ( $VAL->strData1[0] != "" ) { ?>
			<INPUT type=button value=<?= $VAL->strData1[0] ?>
			onClick='OpenWindow( "<?= $VAL->strData1[0] ?>" )'
			>
		<?  } ?>
		&nbsp;</td>
		<td bgcolor=white><?= $VAL->strData2[0] ?>	&nbsp;</td>
		<td bgcolor=white><?= $VAL->nData3[0] ?>	&nbsp;</td>
		<td bgcolor=white><?= $VAL->dtData4[0] ?>	&nbsp;</td>
		<td bgcolor=white><?= $VAL->strData5[0] ?>	&nbsp;</td>
	</tr>
	<!-- row:2 -->
	<tr>
		<td bgcolor=white>
		<? if ( $VAL->strData1[1] != "" ) { ?>
			<INPUT type=button value=<?= $VAL->strData1[1] ?>
			onClick='OpenWindow( "<?= $VAL->strData1[1] ?>" )'
			>
		<?  } ?>
		&nbsp;</td>
		<td bgcolor=white><?= $VAL->strData2[1] ?>	&nbsp;</td>
		<td bgcolor=white><?= $VAL->nData3[1] ?>	&nbsp;</td>
		<td bgcolor=white><?= $VAL->dtData4[1] ?>	&nbsp;</td>
		<td bgcolor=white><?= $VAL->strData5[1] ?>	&nbsp;</td>
	</tr>
	<!-- row:3 -->
	<tr>
		<td bgcolor=white>
		<? if ( $VAL->strData1[2] != "" ) { ?>
			<INPUT type=button value=<?= $VAL->strData1[2] ?>
			onClick='OpenWindow( "<?= $VAL->strData1[2] ?>" )'
			>
		<?  } ?>
		&nbsp;</td>
		<td bgcolor=white><?= $VAL->strData2[2] ?>	&nbsp;</td>
		<td bgcolor=white><?= $VAL->nData3[2] ?>	&nbsp;</td>
		<td bgcolor=white><?= $VAL->dtData4[2] ?>	&nbsp;</td>
		<td bgcolor=white><?= $VAL->strData5[2] ?>	&nbsp;</td>
	</tr>
	<!-- row:4 -->
	<tr>
		<td bgcolor=white>
		<? if ( $VAL->strData1[3] != "" ) { ?>
			<INPUT type=button value=<?= $VAL->strData1[3] ?>
			onClick='OpenWindow( "<?= $VAL->strData1[3] ?>" )'
			>
		<?  } ?>
		&nbsp;</td>
		<td bgcolor=white><?= $VAL->strData2[3] ?>	&nbsp;</td>
		<td bgcolor=white><?= $VAL->nData3[3] ?>	&nbsp;</td>
		<td bgcolor=white><?= $VAL->dtData4[3] ?>	&nbsp;</td>
		<td bgcolor=white><?= $VAL->strData5[3] ?>	&nbsp;</td>
	</tr>
	<!-- row:5 -->
	<tr>
		<td bgcolor=white>
		<? if ( $VAL->strData1[4] != "" ) { ?>
			<INPUT type=button value=<?= $VAL->strData1[4] ?>
			onClick='OpenWindow( "<?= $VAL->strData1[4] ?>" )'
			>
		<?  } ?>
		&nbsp;</td>
		<td bgcolor=white><?= $VAL->strData2[4] ?>	&nbsp;</td>
		<td bgcolor=white><?= $VAL->nData3[4] ?>	&nbsp;</td>
		<td bgcolor=white><?= $VAL->dtData4[4] ?>	&nbsp;</td>
		<td bgcolor=white><?= $VAL->strData5[4] ?>	&nbsp;</td>
	</tr>
</table>
<br>
<table border=0>
	<tr>
		<td>
			<input type="submit"
				name="cmd_send"
				value="Previous"
				style="width:80px">
		</td>
		<td>
			<input type="submit" 
				name="cmd_send" 
				value="Next" 
				style="width:80px">
		</td>
	</tr>
	<tr>
		<td height=20></td>
	</tr>
	<tr>
		<td>StartKey</td>
		<td><input type="text" name="start_key" value="<?= $VAL->StartKey ?>"></td>
	</tr>
	<tr>
		<td>EndKey</td>
		<td><input type="text" name="end_key" value="<?= $VAL->EndKey ?>"></td>
	</tr>
</table>
<br>

</FORM>
</BODY>
</HTML>

<SCRIPT language=JavaScript>

var Handle;

function OpenWindow( strCode ) {


	Handle = window.open(
		"../mtn001/main.php?code=" + strCode
		,"mtn001"
		,"top=0,left=0,height=400,width=400,status=yes,toolbar=no,menubar=no,location=no"
	);

	Handle.window.focus();

}

</SCRIPT>

  

  Window を開けた先のURLでの 「main.php」



  
<?
# **********************************************************
# スクリプト共通変数
# **********************************************************
$Common_dir	= "..\\require\\";
$Title_name	= "学生マスタの更新";
$Form_name	= "frmMain";

# **********************************************************
# 外部ファイル
# **********************************************************
require_once( $Common_dir . "std.php" );
require_once( "value.php" );
require_once( "action.php" );
?>	

<HTML>
<?
# **********************************************************
# スクリプト固有の初期化
# **********************************************************
	$VAL = new PgValue();

# **********************************************************
# HEAD・BODY・FORM
# **********************************************************
?>

<HEAD>
<TITLE><?= $Title_name ?></TITLE>
<STYLE type="text/css">
<? require_once( $Common_dir . "css.php" ) ?>
</STYLE>
</HEAD>
<BODY>
<FORM 
  method=post
  action=<?= $_ENV["SCRIPT_NAME"] . "?code=" . $_GET["code"] ?>
  name=<?= $Form_name?>
  onSubmit="return CheckData();"
>

<?
# **********************************************************
# DB インスタンス
# **********************************************************
	$SQL = new DB( "LAYLA", "WEBDATA", "sa", "" );

# **********************************************************
# 処理コントロール
# **********************************************************
	if ( strtoupper( $_ENV["REQUEST_METHOD"] ) == "GET" ) {
		F_LoadDataInit( $SQL, $VAL );
	}
	else {
		switch( $_POST["cmd_send"] ) {
			case "Update":
				F_UpdateData( $SQL, $VAL );
?>
<SCRIPT language=JavaScript>
var d = new Date()
window.opener.location.search = 'start_key=' 
	+ window.opener.document.all.item('start_key').value
	+ '&reload=' + d.getHours() + d.getMinutes() + d.getSeconds();
window.close();
</SCRIPT>
<?
				break;	
		}
	}	

# **********************************************************
# ビュー
# **********************************************************
	require_once( "view.php" );	

# **********************************************************
# 接続解除
# **********************************************************
	$SQL->Close();
?>

  

  VIEW




  
<?
echo <<<MAIN
<center>
<h1>学生データメンテ</h1>
<table  cellpadding=10>

	<tr>
		<th>コード</th>
		<td bgcolor=white>
		<INPUT name=Code type=text value="{$VAL->strData1}"
		readonly style='background-color:silver'
		>
		</td>
	</tr>
	<tr>
		<th>名前</th>
		<td bgcolor=white>
		<INPUT name=Name type=text value="{$VAL->strData2}">
		</td>
	</tr>
	<tr>
		<th>学年</th>
		<td bgcolor=white>
		<INPUT name=Nen type=text value="{$VAL->nData3}">
		</td>
	</tr>
	<tr>
		<th>誕生日</th>
		<td bgcolor=white>
		<INPUT name=Date type=text value="{$VAL->dtData4}">
		</td>
	</tr>
	<tr>
		<th>電話番号</th>
		<td bgcolor=white>
		<INPUT name=Tel type=text value="{$VAL->strData5}">
		</td>
	</tr>

</table>
<br>
<table border=0>
	<tr>
		<td>
			<input type="submit"
				name="cmd_send"
				value="Update"
				style="width:80px">
		</td>
		<td>
			<input type="button"
				name="Cancel"
				value="Cancel"
				style="width:80px;background-color:pink"
				onClick='window.close();'
			>
		</td>
	</tr>
</table>
<br>

</FORM>
</BODY>
</HTML>

<SCRIPT language=JavaScript>

function CheckData() {

	if ( !confirm( "更新しますか?" ) ) {
		return false;
	}

	return true;

}

</SCRIPT>

<SCRIPT FOR=window EVENT=onload LANGUAGE="JavaScript">

	document.frmMain.Name.focus();
	document.frmMain.Name.select();

</SCRIPT>

MAIN;
?>

  

  action.php

  
<?

$Column_list	= "コード,名前,学年,convert(char(10),誕生日,111),電話番号";
$Main_table	= "学生マスタ";
$Key_code	= "コード";

# *********************************************************
# データセット
# *********************************************************
function F_SetData( &$SQL, &$VAL ) {

	if ( FALSE == $SQL->Fetch() ) {
		return 0;
	}

	$VAL->strData1		= $SQL->Field[0];
	$VAL->strData2		= $SQL->Field[1];
	$VAL->nData3		= $SQL->Field[2];
	$VAL->dtData4		= str_replace( "/", "", $SQL->Field[3] );
	$VAL->strData5		= $SQL->Field[4];

	return 1;
}

# *********************************************************
# 初期データ・カレントデータ
# *********************************************************
function F_LoadDataInit( &$SQL, &$VAL ) {

	$SqlQuery = "select {$GLOBALS["Column_list"]}";
	$SqlQuery .= " from {$GLOBALS["Main_table"]}";
	$SqlQuery .= " where {$GLOBALS["Key_code"]} = '{$_GET["code"]}'";
	$SQL->Query( $SqlQuery );

	F_SetData( $SQL, $VAL );
	$SQL->Free();
}

# *********************************************************
# 更新処理
# *********************************************************
function F_UpdateData( &$SQL, &$VAL ) {

	$SqlUpdate = "update {$GLOBALS["Main_table"]} set ";
	$SqlUpdate .= "名前 = '{$_POST["Name"]}'";
	$SqlUpdate .= ",学年 = {$_POST["Nen"]}";
	$SqlUpdate .= ",誕生日 = convert(char(10),'{$_POST["Date"]}',111)";
	$SqlUpdate .= ",電話番号 = '{$_POST["Tel"]}'";
	$SqlUpdate .= " where {$GLOBALS["Key_code"]} = '{$_GET["code"]}'";

	$SQL->Execute( $SqlUpdate );

}

?>

  











   SQLの窓    create:2002/09/18  update:2014/09/07   管理者用(要ログイン)





フリーフォントWEBサービス

SQLの窓WEBサービス

SQLの窓フリーソフト

写真素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ