여분필드를 배열로 해서 문제 입력항목을 만들었는데 for문으로 돌릴수 있나요?
본문
여분필드를 이용하여 아래와 같이 문제입력항목을 만들었는데 30문항 정도해야해서 아래 것을 30번 복사하여 수정하기가 어려워서 for문으로 할 수 있나해서 질문올립니다.
quizq[0] ~ quizq[30] 까지 반복 될 때 대괄호 안을 어떻게 처리할지 몰라서 질문올립니다 도움 부탁합니다
<!----1번 문제{---->
<span class="badge text-bg-primary rounded-0">1번</span>
<div class="row g-0 p-2">
<div class="col-md-1 py-1">문제</div>
<div class="col-md-11 py-1 clearfix">
<textarea type="text" id="m_input" name="quizq[0]" value="<?php echo $quizq[0] ?>" class="required form-control border border-secondary" rows="2" maxlength="2550"><?php echo $quizq[0] ?></textarea>
</div>
</div>
<div class="row g-0 p-2">
<div class="col-md-1 py-1">정답</div>
<div class="col-md-2 py-1 clearfix">
<input type="radio" id="m_input" name="quiza[0]" value="o"<?php echo ($quiza[0] == "o") ? " checked" : "";?> class="frm_input border border-secondary" >o
<input type="radio" id="m_input" name="quiza[0]" value="x"<?php echo ($quiza[0] == "x") ? " checked" : "";?> class="frm_input border border-secondary" >x
</div>
</div>
<!----1번 문제}---->
답변 4
<?php for ($i = 0; $i < 30; $i++) { ?>
<span class="badge text-bg-primary rounded-0">1번</span>
<div class="row g-0 p-2">
<div class="col-md-1 py-1">문제</div>
<div class="col-md-11 py-1 clearfix">
<textarea type="text" id="m_input" name="quizq[<?php echo $i ?>]" value="<?php echo $quizq[$i] ?>" class="required form-control border border-secondary" rows="2" maxlength="2550"><?php echo $quizq[$i] ?></textarea>
</div>
</div>
<div class="row g-0 p-2">
<div class="col-md-1 py-1">정답</div>
<div class="col-md-2 py-1 clearfix">
<input type="radio" id="m_input" name="quiza[<?php echo $i ?>]" value="o"<?php echo ($quiza[$i] == "o") ? " checked" : "";?> class="frm_input border border-secondary" >o
<input type="radio" id="m_input" name="quiza[<?php echo $i ?>]" value="x"<?php echo ($quiza[$i] == "x") ? " checked" : "";?> class="frm_input border border-secondary" >x
</div>
</div>
<?php } ?>
<?php for ($i = 0; $i < 30; $i++) { ?>
<span class="badge text-bg-primary rounded-0"><?php echo $i + 1 ?>번</span>
<div class="row g-0 p-2">
<div class="col-md-1 py-1">문제</div>
<div class="col-md-11 py-1 clearfix">
<textarea type="text" id="m_input" name="quizq[<?php echo $i ?>]" value="<?php echo $quizq[$i] ?>" class="required form-control border border-secondary" rows="2" maxlength="2550"><?php echo $quizq[$i] ?></textarea>
</div>
</div>
<div class="row g-0 p-2">
<div class="col-md-1 py-1">정답</div>
<div class="col-md-2 py-1 clearfix">
<input type="radio" id="m_input" name="quiza[<?php echo $i ?>]" value="o"<?php echo ($quiza[$i] == "o") ? " checked" : "";?> class="frm_input border border-secondary" >o
<input type="radio" id="m_input" name="quiza[<?php echo $i ?>]" value="x"<?php echo ($quiza[$i] == "x") ? " checked" : "";?> class="frm_input border border-secondary" >x
</div>
</div>
<?php } ?>
별도 테이블을 만드는 것을 추천합니다
답변을 작성하시기 전에 로그인 해주세요.