TIP게시판

제목 테이블 칼럼이름값 자동으로 가져오기
글쓴이 이지포토 작성시각 2012/12/10 12:20:53
댓글 : 0 추천 : 0 스크랩 : 0 조회수 : 13955   RSS
컨트롤:

 function popdetail($idxNo)
 {

  $this->form_validation->set_rules('mb_email', '  ** 메일', 'required');
  $this->form_validation->set_rules('mb_level', '  ** 레벨', 'required');
  $this->form_validation->set_rules('mb_birth', '  ** 생일', 'required');

  if ($this->form_validation->run('mb_no') == false){


   $data['col_name'] = array('mb_id','mb_password','mb_name','mb_nick','mb_nick_date','mb_email','mb_homepage','mb_password_q','mb_password_a','mb_level','mb_jumin','mb_sex','mb_birth','mb_tel','mb_hp','mb_zip1','mb_zip2','mb_addr1','mb_addr2','mb_signature','mb_recommend','mb_point','mb_today_login','mb_login_ip','mb_datetime','mb_ip','mb_leave_date','mb_intercept_date','mb_email_certify','mb_memo','mb_mailling','mb_sms','mb_open','mb_open_date','mb_profile');
   $data['col'] = $this->mem_model->column_name();
   $data['row'] = $this->mem_model->kcGetData($idxNo);
   $data['post_link'] = '/admin/member/popdetail/'.$this->uri->segment(4);
   $this->load->view('admin/member/pop_member_detail_view', $data);
  }else{
   $urlp = "/admin/member/popdetail/".$this->uri->segment(4);
   $this->mem_model->kcUpdate($this->uri->segment(4)); 
   redirect($urlp);          
  }
 }



모델:

 function column_name(){  
   return cN($this->table_name) ;
  }


 function kcGetData($Idx)
 {
  $this->db->select('*');
  $this->db->where("mb_no", $Idx);
  $query = $this->db->get($this->table_name);
  //echo $this->db->last_query();
  return $query->row_array();
 }

Helper :
function cN($table){  
  $CI = & get_instance();
   $sql="SELECT column_name, column_comment FROM information_schema.columns WHERE table_name='".$table."' ";  
   $query=$CI->db->query($sql); // echo $CI->db->last_query();
   
   foreach ($query->result_array() as $key => $row)   {  
    if($row['column_comment']){
    $column_comment[$row['column_name']]=$row['column_comment'];  
    }
   }
   return $column_comment ;
  }


뷰:

<form id="aform" name="aform" method="post" action="<?=$post_link;?>"   accept-charset="utf-8">

<input type="hidden" name="mb_no" value="<?=$this->uri->segment(4)?>">
<table width="80%" border="0" cellpadding="0" cellspacing="0" style="padding-right: 5pt"  style="word-break:break-all">
<? 
for($i=0;$i<count($col_name);$i++){

 if($col_name[$i] == 'mb_id' || $col_name[$i] == 'mb_password' || $col_name[$i] == 'mb_name'){ $field_text = $row[$col_name[$i]]; 
 }else{ $field_text = "<input type=\"text\" name='".$col_name[$i]."' value='".$row[$col_name[$i]]."'>";
 }  
?>
    <tr><td align="left" class='table_input_gubun' width='100'><?=$col[$col_name[$i]]?></td>
 <td width="3"> </td>
 <td><?=$field_text ?><!-- <input type="text" name='<?=$col_name[$i]?>' value='<?=$row[$col_name[$i]]?>'> --></td>
 </tr>
 <tr height="2"><td colspan="3"></td></tr>   
<?}?>
</table></form>
<script src="/js/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript" charset="utf-8"></script> 
<script type="text/javascript" charset="utf-8"> $('tr:odd').css('background', '#e3e3e3');</script>
<br />
  <input type="button" name="button2" id="button2" value="닫기" class="btn_search" onclick="[removed]self.close();" />
  <input type="submit" name="button" id="button" value="변경" class="btn_search" onclick="[removed]document.aform.submit();"/>



//일전에 질문게시판에 올렸었는데 웅파님께서 방법을 알려 주셔서 한번 만들어 보았습니다.
응용하면 심풀하게 프로그래밍할수 있을것 같네요.
혹시 더 좋은 방법이 있다면 지적해 주세요.
 다음글 연관배열 vs 객체 (13)
 이전글 세션값을 체크 또는 id로 member 정보 자동으로...

댓글

없음