여분필드안에 숫자 더하기
본문
게시판 리스트에 여분필드를 사용하여 총 수량을 구하고싶은데 초보자라 너무 막히는 부분이 많습니다..고수님들의 조언 부탁드립니다ㅠㅠㅠㅠ
<ul class="che_box">
<li class="">
<input type="checkbox" name="wr_1" id="cho_1" value="품목 명1" <?php echo get_checked($write['wr_1'], '선택1'); ?>>
<label for="cho_1">
품목 명1
</label>
</li>
<li>
<input type="checkbox" name="wr_2" id="cho_2" value="품목 명2" <?php echo get_checked($write['wr_2'], '선택2'); ?>>
<label for="cho_2">
품목 명2
</label>
</li>
<li>
<input type="checkbox" name="wr_3" id="cho_3" value="품목 명3" <?php echo get_checked($write['wr_3'], '선택3'); ?>>
<label for="cho_3">
품목 명3
</label>
</li>
<li>
<input type="checkbox" name="wr_4" id="cho_4" value="품목 명4" <?php echo get_checked($write['wr_4'], '선택4'); ?>>
<label for="cho_4">
품목 명4
</label>
</li>
<li>
<input type="checkbox" name="wr_5" id="cho_5" value="품목 명5" <?php echo get_checked($write['wr_5'], '선택5'); ?>>
<label for="cho_5">
품목 명5
</label>
</li>
<li>
<input type="checkbox" name="wr_6" id="cho_6" value="품목 명6" <?php echo get_checked($write['wr_6'], '선택6'); ?>>
<label for="cho_6">
품목 명6
</label>
</li>
<li>
<input type="checkbox" name="wr_7" id="cho_7" value="품목 명7" <?php echo get_checked($write['wr_7'], '선택7'); ?>>
<label for="cho_7">
품목 명7
</label>
</li>
<li>
<input type="checkbox" name="wr_8" id="cho_8" value="품목 명8"<?php echo get_checked($write['wr_8'], '선택8'); ?>>
<label for="cho_8">
품목 명8
</label>
</li>
</ul>
</fieldset>
<div id="hide_1" style="display:none;">
<p class="hide_1">품목 명1</p>
<input type="number" pattern="\d*" placeholder="취소 시 숫자를 지워수세요."name="wr_9" id="cho_9" value="0" <?php echo get_checked($write['wr_9'], '선택9'); ?>>KG
</div>
<div id="hide_2" style="display:none;">
<p class="hide_1">품목 명2</p>
<input type="number" pattern="\d*" placeholder="취소 시 숫자를 지워수세요."name="wr_10" id="cho_10" value="0" <?php echo get_checked($write['wr_10'], '선택10'); ?>>KG
</div>
<div id="hide_3" style="display:none;">
<p class="hide_1">품목 명3</p>
<input type="number" pattern="\d*" placeholder="취소 시 숫자를 지워수세요."name="wr_11" id="cho_11" value="0" <?php echo get_checked($write['wr_11'], '선택11'); ?>>KG
</div>
<div id="hide_4" style="display:none;">
<p class="hide_1">품목 명4</p>
<input type="number" pattern="\d*" placeholder="취소 시 숫자를 지워수세요."name="wr_12" id="cho_12" value="0" <?php echo get_checked($write['wr_12'], '선택12'); ?>>KG
</div>
<div id="hide_5" style="display:none;">
<p class="hide_5">품목 명5</p>
<input type="number" pattern="\d*" placeholder="취소 시 숫자를 지워수세요."name="wr_13" id="cho_13" value="0" <?php echo get_checked($write['wr_13'], '선택13'); ?>>KG
</div>
<div id="hide_6" style="display:none;">
<p class="hide_1">품목 명6</p>
<input type="number" pattern="\d*" placeholder="취소 시 숫자를 지워수세요."name="wr_14" id="cho_14" value="0" <?php echo get_checked($write['wr_14'], '선택14'); ?>>KG
</div>
<div id="hide_7" style="display:none;">
<p class="hide_1">품목 명7</p>
<input type="number" pattern="\d*" placeholder="취소 시 숫자를 지워수세요."name="wr_15" id="cho_15" value="0" <?php echo get_checked($write['wr_15'], '선택15'); ?>>KG
</div>
<div id="hide_8" style="display:none;">
<p class="hide_1">품목 명8</p>
<input type="number" pattern="\d*" placeholder="취소 시 숫자를 지워수세요."name="wr_16" id="cho_16" value="0" <?php echo get_checked($write['wr_16'], '선택16'); ?>>KG
</div>
<a href="<?php echo $list[$i]['href'] ?>">
<?php echo $list[$i]['wr_1'] , $list[$i]['wr_9'] ?>
<?php echo $list[$i]['wr_2'] ?><?php echo $list[$i]['wr_10'] ?>
<?php echo $list[$i]['wr_3'] ?><?php echo $list[$i]['wr_11'] ?>
<?php echo $list[$i]['wr_4'] ?><?php echo $list[$i]['wr_12'] ?>
<?php echo $list[$i]['wr_5'] ?><?php echo $list[$i]['wr_13'] ?>
<?php echo $list[$i]['wr_6'] ?><?php echo $list[$i]['wr_14'] ?>
<?php echo $list[$i]['wr_7'] ?><?php echo $list[$i]['wr_15'] ?>
<?php echo $list[$i]['wr_8'] ?><?php echo $list[$i]['wr_16'] ?>
<?php if ($list[$i]['comment_cnt']) { ?><span class="sound_only">댓글</span><?php echo $list[$i]['comment_cnt']; ?><span class="sound_only">개</span><?php } ?>
</a>
<?php
// if ($list[$i]['link']['count']) { echo '['.$list[$i]['link']['count']}.']'; }
// if ($list[$i]['file']['count']) { echo '<'.$list[$i]['file']['count'].'>'; }
if (isset($list[$i]['icon_new'])) echo $list[$i]['icon_new'];
if (isset($list[$i]['icon_hot'])) echo $list[$i]['icon_hot'];
if (isset($list[$i]['icon_file'])) echo $list[$i]['icon_file'];
if (isset($list[$i]['icon_link'])) echo $list[$i]['icon_link'];
if (isset($list[$i]['icon_secret'])) echo $list[$i]['icon_secret'];
?>
</td>
<?php $sum = $view['wr_9'] + $view['wr_10'] + $view['wr_11'] + $view['wr_12'] + $view['wr_13'] + $view['wr_14'] + $view['wr_15'] + $view['wr_16'];?>
<td class="want_td2 sv_use"><?php echo $sum?>KG</td>
답변 4
위의 내용중에
<?php $sum = $view['wr_9'] + $view['wr_10'] + $view['wr_11'] + $view['wr_12'] + $view['wr_13'] + $view['wr_14'] + $view['wr_15'] + $view['wr_16'];?>
<table><tr><td class="want_td2 sv_use"><?php echo $sum?>KG</td></tr></table>
이영역으 다음과 같이 변경해보세요
<?php
$sum = 0;
for($j = 9; $j <=16; $j++) { // 확장컬럼의 증가숫자가 일련번호형일때 9~16까지
$sum += intval($list[$i]['wr_'.$j]); //문자형인경우 intval()로 숫자(interger)형으로 변경후 합산
}
?>
<table><tr><td class="want_td2 sv_use"><?php echo $sum?>KG</td></tr></table>
$view 가 선언되지 않은것 아닌가요?
단순히 아래처럼 하면 값은 나옵니다.
<?php
$view = array(
'wr_9' => 1,
'wr_10' => 1,
'wr_11' => 1,
'wr_12' => 1,
'wr_13' => 1,
'wr_14' => 1,
'wr_15' => 1,
'wr_16' => 1,
);
?>
<?php $sum = $view['wr_9'] + $view['wr_10'] + $view['wr_11'] + $view['wr_12'] + $view['wr_13'] + $view['wr_14'] + $view['wr_15'] + $view['wr_16'];?>
<table><tr><td class="want_td2 sv_use"><?php echo $sum?>KG</td></tr></table>
$list와 $view를 같이 사용하는 곳이
어떤 페이지(file)인가요?
$view를 $list[ $i]로 바꿔 보세요
$view는 상세보기에 사용하는 배열 입니다.
<?php $sum = $view['wr_9'] + $view['wr_10'] + $view['wr_11'] + $view['wr_12'] + $view['wr_13'] + $view['wr_14'] + $view['wr_15'] + $view['wr_16'];?>
<td class="want_td2 sv_use"><?php echo $sum?>KG</td>
를
<?php $sum = $list[$i]['wr_9'] + $list[$i]['wr_10'] + $list[$i]['wr_11'] + $list[$i]['wr_12'] + $list[$i]['wr_13'] + $list[$i]['wr_14'] + $list[$i]['wr_15'] + $list[$i]['wr_16'];?> <td class="want_td2 sv_use"><?php echo $sum?>KG</td>
로 변경해 보십시요
답변을 작성하시기 전에 로그인 해주세요.