親画面
js
1 <script type="text/javascript"> 2 function disp(url,windowname,width,height) { 3 var features="location=no, menubar=no, status=yes, scrollbars=yes, resizable=yes, toolbar=no"; 4 if (width) { 5 if (window.screen.width > width) 6 features+=", left="+(window.screen.width-width)/8; 7 else width=window.screen.width; 8 features+=", width="+width; 9 } 10 if (height) { 11 if (window.screen.height > height) 12 features+=", top="+(window.screen.height-height)/8; 13 else height=window.screen.height; 14 features+=", height="+height; 15 } 16 window.open(url, "サブ検索画面", "width=600,height=600"); 17 } 18 </script>
html
1<input name="SearchScreen" type="button" value="検索" onClick='disp("/SubScreen1.php")' /> 2 <input id="code1" type="text" size="20" value="" /> 3 <input id="code2" type="text" size="15" vallue="" /> 4 <input id="code3" type="text" value="" />
以下、子画面
php
1<?php 2 3//データベース接続・・省略 4 5if ($mysqli->connect_error){ 6 echo $mysqli->connect_error; 7 exit(); 8}else{ 9 $mysqli->set_charset("utf-8"); 10} 11 12//FROMの後にDB名 13$sql = "SELECT * FROM `management` ORDER BY `management`.`manage_kana` ASC"; 14 15$result = $mysqli -> query($sql); 16 17//クエリー失敗 18if(!$result) { 19 echo $mysqli->error; 20 exit(); 21} 22 23//レコード件数 24$row_count = $result->num_rows; 25 26//連想配列で取得 27while($row = $result->fetch_array(MYSQLI_ASSOC)){ 28 $rows[] = $row; 29} 30 31//結果セットを解放 32$result->free(); 33 34// データベース切断 35$mysqli->close(); 36 37?> 38
js
1<!-- ポップアップスクリプト --> 2<script type="text/javascript"> 3<!-- 4var parantExistanceFlag = true; 5 6function clickFire(){ 7 8 //ウィンドウオブジェクトが存在していない時警告してフラグをfalseに 9 if ( !window.opener || !Object.keys(window.opener).length ) { 10 window.alert('親画面が存在しません') 11 parantExistanceFlag = false 12 } 13 14 //親画面に値を挿入 15 if(parantExistanceFlag){ 16 window.opener.document.getElementById("code1").value 17 = document.getElementById("searchCode1").value 18 19 window.opener.document.getElementById("code2").value 20 = document.getElementById("searchCode2").value 21 22 window.opener.document.getElementById("code3").value 23 = document.getElementById("searchCode3").value 24 } 25 26 27 window.close(); 28} 29 30 --> 31</script>
html
1<table class="table-design" style="font-size: 10pt; "> 2 <thead> 3 <tr> 4 <th></th> 5 <th>選択</th> 6 <th>人物名</th> 7 <th>TEL</th> 8 <th>address</th> 9 </tr> 10 </thead> 11<tbody> 12<?php 13foreach($rows as $row){ 14 echo '<tr>'; 15 echo '<td><center>■</center></td>'; 16 echo '<input id="searchCode1" type="hidden" value="',$row['aaa001'],'">'; 17 echo '<td><input type="submit" name="select" value="選択" onClick="clickFire()"/></td>'; 18 echo '<td>', $row['aaa001'], '</td>'; 19 echo '<input id="searchCode2" type="hidden" value="',$row['aaa_tel1'],'-',$row['aaa_tel2'],'-',$row['aaa_tel3'],'">'; 20 echo '<td>', $row['aaa_tel1'], '-', $row['aaa_tel2'], '-', $row['aaa_tel3'], '</td>'; 21 echo '<input id="searchCode3" type="hidden" value="',$row['aaa_fax1'],'-',$row['aaa_fax2'],'-',$row['aaa_fax3'],'">'; 22 echo '<td>', $row['aaa_fax1'], '-', $row['aaa_fax2'], '-', $row['aaa_fax3'], '</td>'; 23 echo '<input id="mb_id" type="hidden" value="',$row['aaa_id'],'">'; 24 echo '</tr>'; 25 } 26?> 27</tbody> 28</table>
このコードではどれを選択してもDB内の最初のカラムしか表示されず
それぞれを正しく選択・表示させるにはどう記述するべきなのでしょうか?
回答1件
あなたの回答
tips
プレビュー