디비연동이 필요한 셀렉트박스 함수로 지정
/*
셀렉트 박스 생성 함수
필수인자: 1. 테이블명, 2. 컬럼명
선택인자: 3. select의 name이 다를경우, 4. 기초값 5. 조건문, 6. 추가함수
*/
function make_selectBox($table, $colName, $insertName, $selectedVal='', $where='', $addFunction=''){
$html = "<option value=''>- 선택하세요 -</option>";
$idx_num = 0;
$col_num = 0;
if( is_array($colName) ){
$col_num = 1;
$cols = implode(',', $colName);
}else{
$cols = $colName;
}
$sql = "select $cols from $table $where";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
$selected = '';
if( $row[$idx_num] == $selectedVal && $selectedVal != '' ) $selected = 'selected';
$html.= "<option value='{$row[$idx_num]}' {$selected}>{$row[$col_num]}</option>";
}
if( $insertName != '' ) $idx_name = $insertName;
echo "<select name='{$insertName}' id='{$insertName}' {$addFunction}>".$html."</select>";
unset($html);
}
ex) <?=make_selectBox("shop_site_code", array('index_no','site_name'),'site_code')?>
두번째 인자는 value와 txt가 같다면 array가아닌 단일 컬럼명으로 지정한다.