DB table 컬럼 비교

컬럼이 비슷한 테이블을 비교합니다.

<?php
include '_common.php';
$get_constant = 'constant';
$this_db= G5_MYSQL_DB;

?>
<div >
<form >
<input type="text" name="tbl1" value="<?=$tbl1?>" placeholder="table1" />
<input type="text" name="tbl2" value="<?=$tbl2?>" placeholder="table2" />
<input type="submit" />
</form>
</div>
<?php

if( $tbl1 & $tbl2 ) {

echo '<table>';

$sql="SELECT a.COLUMN_NAME acols, b.COLUMN_NAME bcols   FROM INFORMATION_SCHEMA.COLUMNS a  left join INFORMATION_SCHEMA.COLUMNS b
 on a.TABLE_name='{$tbl1}' and b.TABLE_NAME='{$tbl2}'
 and a.COLUMN_NAME=b.COLUMN_NAME
WHERE a.TABLE_SCHEMA = '{$get_constant('G5_MYSQL_DB')}' AND a.TABLE_NAME = '{$tbl1}'
union
SELECT a.COLUMN_NAME acols, b.COLUMN_NAME bcols  FROM INFORMATION_SCHEMA.COLUMNS a  right join INFORMATION_SCHEMA.COLUMNS b
 on a.TABLE_name='{$tbl1}' and b.TABLE_NAME='{$tbl2}'
 and a.COLUMN_NAME=b.COLUMN_NAME
WHERE b.TABLE_SCHEMA = '{$get_constant('G5_MYSQL_DB')}' AND b.TABLE_NAME = '{$tbl2}'
";
$result= sql_query( $sql);
$ins_set=array();
$sel_set=array();
echo '<table>';
if( $result) while( $row= sql_fetch_array( $result)) {
        $ins_set[]= $row['acols']?$row['acols']:"''";
        $sel_set[]= $row['bcols']?$row['bcols']:"''";
        echo '<tr><td bgcolor="'.($row['acols']?'':'#d3f9d8').'" >',$row['acols'],'</td><td bgcolor="'.($row['bcols']?'':'#d3f9d8').'" >',$row['bcols'],'</td></tr>';
}
echo '</table>';

echo 'ok';

}

|

댓글 2개

감사합니다
저에게도 도움이 될 것 같습니다
댓글을 작성하시려면 로그인이 필요합니다. 로그인

그누보드5 팁자료실

+
제목 글쓴이 날짜 조회
4년 전 조회 5,017
4년 전 조회 3,934
4년 전 조회 4,000
4년 전 조회 4,101
4년 전 조회 3,690
4년 전 조회 3,814
4년 전 조회 2,914
4년 전 조회 6,471
4년 전 조회 3,057
4년 전 조회 4,712
4년 전 조회 3,389
4년 전 조회 3,324
4년 전 조회 3,939
4년 전 조회 3,215
4년 전 조회 2,978
4년 전 조회 3,508
4년 전 조회 5,660
4년 전 조회 2,891
4년 전 조회 3,565
4년 전 조회 2,996
4년 전 조회 3,753
4년 전 조회 3,439
4년 전 조회 2,466
4년 전 조회 4,893
4년 전 조회 3,998
4년 전 조회 3,638
4년 전 조회 3,610
4년 전 조회 4,905
4년 전 조회 3,504
4년 전 조회 3,379
🐛 버그신고