계층(배열)로 소스를 정리할 수 있을까요?

계층(배열)로 소스를 정리할 수 있을까요?

QA

계층(배열)로 소스를 정리할 수 있을까요?

답변 1

본문

63c0467f9e420063de2eb4ff84e88ff3_1491842624_7204.jpg----------------------------------------------------------------------

위에 처럼 구현하기 위해서 제가 배열등을 이해하지 못해서 소스를 아주 무식하게 사용하였습니다

아래와 같은 소스를 좀 간결하면서도 정렬을 시킬수 있을까 싶어서 도움을 요청합니다

또한 수정을 하면 선택한 라디오버튼이 아닌 처음 "창세기"부분이 선택되어 있군요

계층 카테고리 및 배열은 봐도 잘 이해를 못하겠더군요

위에처럼 구현한 이유는

창세기를 선택했을때 wr_1=창 값을 넣기 위해서 입니다

 

 

 

 




               <?
    $wr_1 = explode("|", $write[wr_1]);
              ?>
     <input type="radio" name="wr_1" value="창" <?if($wr_1[0]):?> checked<?endif;?>>창세기
     <input type="radio" name="wr_1" value="출" <?if($wr_1[1]):?> checked<?endif;?>>출애굽기
     <input type="radio" name="wr_1" value="레" <?if($wr_1[2]):?> checked<?endif;?>>레위기
     <input type="radio" name="wr_1" value="민" <?if($wr_1[3]):?> checked<?endif;?>>민수기​
     <input type="radio" name="wr_1" value="신" <?if($wr_1[4]):?> checked<?endif;?>>신명기     
     <input type="radio" name="wr_1" value="수" <?if($wr_1[5]):?> checked<?endif;?>>여호수아​
     <input type="radio" name="wr_1" value="삿" <?if($wr_1[6]):?> checked<?endif;?>>사사기
     <input type="radio" name="wr_1" value="롯" <?if($wr_1[7]):?> checked<?endif;?>>룻기
     <input type="radio" name="wr_1" value="삼상" <?if($wr_1[8]):?> checked<?endif;?>>사무엘상
     <input type="radio" name="wr_1" value="삼하" <?if($wr_1[9]):?> checked<?endif;?>>사무엘하
     <input type="radio" name="wr_1" value="왕상" <?if($wr_1[10]):?> checked<?endif;?>>열왕기상
     <input type="radio" name="wr_1" value="왕하" <?if($wr_1[11]):?> checked<?endif;?>>열왕기하<p>
     <input type="radio" name="wr_1" value="대상" <?if($wr_1[12]):?> checked<?endif;?>>역대상
     <input type="radio" name="wr_1" value="대하" <?if($wr_1[13]):?> checked<?endif;?>>역대하
     <input type="radio" name="wr_1" value="스" <?if($wr_1[14]):?> checked<?endif;?>>에스라
     <input type="radio" name="wr_1" value="느" <?if($wr_1[15]):?> checked<?endif;?>>느헤미야
     <input type="radio" name="wr_1" value="에" <?if($wr_1[16]):?> checked<?endif;?>>에스더
     <input type="radio" name="wr_1" value="욥" <?if($wr_1[17]):?> checked<?endif;?>>욥기
     <input type="radio" name="wr_1" value="시" <?if($wr_1[18]):?> checked<?endif;?>>시편
     <input type="radio" name="wr_1" value="잠" <?if($wr_1[19]):?> checked<?endif;?>>잠언
     <input type="radio" name="wr_1" value="전" <?if($wr_1[21]):?> checked<?endif;?>>전도서
     <input type="radio" name="wr_1" value="아" <?if($wr_1[22]):?> checked<?endif;?>>아가
     <input type="radio" name="wr_1" value="사" <?if($wr_1[23]):?> checked<?endif;?>>이사야
     <input type="radio" name="wr_1" value="렘" <?if($wr_1[24]):?> checked<?endif;?>>예레미야     
     <input type="radio" name="wr_1" value="애" <?if($wr_1[25]):?> checked<?endif;?>>예레미야애가
     <input type="radio" name="wr_1" value="겔" <?if($wr_1[26]):?> checked<?endif;?>>에스겔
     <input type="radio" name="wr_1" value="단" <?if($wr_1[27]):?> checked<?endif;?>>다니엘    
     <input type="radio" name="wr_1" value="호" <?if($wr_1[28]):?> checked<?endif;?>>호세아
     <input type="radio" name="wr_1" value="욜" <?if($wr_1[29]):?> checked<?endif;?>>요엘
     <input type="radio" name="wr_1" value="암" <?if($wr_1[30]):?> checked<?endif;?>>아모스
     <input type="radio" name="wr_1" value="옵" <?if($wr_1[31]):?> checked<?endif;?>>오바댜
     <input type="radio" name="wr_1" value="욘" <?if($wr_1[32]):?> checked<?endif;?>>요나
     <input type="radio" name="wr_1" value="미" <?if($wr_1[33]):?> checked<?endif;?>>미가
     <input type="radio" name="wr_1" value="나" <?if($wr_1[34]):?> checked<?endif;?>>나훔
     <input type="radio" name="wr_1" value="합" <?if($wr_1[35]):?> checked<?endif;?>>하박국
     <input type="radio" name="wr_1" value="습" <?if($wr_1[36]):?> checked<?endif;?>>스바냐
     <input type="radio" name="wr_1" value="학" <?if($wr_1[37]):?> checked<?endif;?>>학개
     <input type="radio" name="wr_1" value="슥" <?if($wr_1[38]):?> checked<?endif;?>>스가랴      
     <input type="radio" name="wr_1" value="말" <?if($wr_1[39]):?> checked<?endif;?>>말라기<P>

     <input type="radio" name="wr_1" value="마" <?if($wr_1[40]):?> checked<?endif;?>>마태복음
     <input type="radio" name="wr_1" value="막" <?if($wr_1[41]):?> checked<?endif;?>>마가복음        
     <input type="radio" name="wr_1" value="눅" <?if($wr_1[42]):?> checked<?endif;?>>누가복음                 
     <input type="radio" name="wr_1" value="요" <?if($wr_1[43]):?> checked<?endif;?>>요한복음                 
     <input type="radio" name="wr_1" value="행" <?if($wr_1[44]):?> checked<?endif;?>>사도행전
     <input type="radio" name="wr_1" value="롬" <?if($wr_1[45]):?> checked<?endif;?>>로마서   
     <input type="radio" name="wr_1" value="고전" <?if($wr_1[46]):?> checked<?endif;?>>고린도전서   
     <input type="radio" name="wr_1" value="고후" <?if($wr_1[47]):?> checked<?endif;?>>고린도후서   
     <input type="radio" name="wr_1" value="갈" <?if($wr_1[48]):?> checked<?endif;?>>갈라디아서   
     <input type="radio" name="wr_1" value="엡" <?if($wr_1[49]):?> checked<?endif;?>>에베소서<p>  
     <input type="radio" name="wr_1" value="빌" <?if($wr_1[50]):?> checked<?endif;?>>빌립보서
     <input type="radio" name="wr_1" value="골" <?if($wr_1[51]):?> checked<?endif;?>>골로새서        
     <input type="radio" name="wr_1" value="살전" <?if($wr_1[52]):?> checked<?endif;?>>데살로니가전서                 
     <input type="radio" name="wr_1" value="살후" <?if($wr_1[53]):?> checked<?endif;?>>데살로니가후서                 
     <input type="radio" name="wr_1" value="딤전" <?if($wr_1[54]):?> checked<?endif;?>>디모데전서
     <input type="radio" name="wr_1" value="딤후" <?if($wr_1[55]):?> checked<?endif;?>>디모데후서   
     <input type="radio" name="wr_1" value="딛" <?if($wr_1[56]):?> checked<?endif;?>>디도서   
     <input type="radio" name="wr_1" value="몬" <?if($wr_1[57]):?> checked<?endif;?>>빌레몬서   
     <input type="radio" name="wr_1" value="히" <?if($wr_1[58]):?> checked<?endif;?>>히브리서<p>   
     <input type="radio" name="wr_1" value="약" <?if($wr_1[59]):?> checked<?endif;?>>야고보서   
     <input type="radio" name="wr_1" value="벧전" <?if($wr_1[60]):?> checked<?endif;?>>베드로전서   
     <input type="radio" name="wr_1" value="벧후" <?if($wr_1[61]):?> checked<?endif;?>>베드로후서    
     <input type="radio" name="wr_1" value="요일" <?if($wr_1[62]):?> checked<?endif;?>>요한1서   
     <input type="radio" name="wr_1" value="요이" <?if($wr_1[63]):?> checked<?endif;?>>요한2서    
     <input type="radio" name="wr_1" value="요삼" <?if($wr_1[64]):?> checked<?endif;?>>요한3서   
     <input type="radio" name="wr_1" value="유" <?if($wr_1[65]):?> checked<?endif;?>>유다서    
     <input type="radio" name="wr_1" value="계" <?if($wr_1[66]):?> checked<?endif;?>>요한계시록
 
 


 

이 질문에 댓글 쓰기 :

답변 1

 
배열로 미리 정의하시고요.

for문을 돌면서 input radio 값 출력 

그리고 페이지 로딩시 스크립트 단에서 체크해주시면 됩니다.

 

테스트 없이 코딩한거라 오타가 있을 수 있습니다.

 


<?
 
 $sungkyung = array("창"=>"창세기", "출"=>"출애굽기"); 
 foreach($sungkyung  as $key=>$val)
 {
 echo "<input type='radio' name='wr_1' value='" . $key . "'/>" . $val ;
 }
?>
<script>
$(function(){
 $(":input[name='wr_1'][value='<?=$write['wr_1']?>']").attr("checked",true);
});
</script>

 
답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 9
© SIRSOFT
현재 페이지 제일 처음으로