질문
본문
카테고리별로 포인트를 지정하게 해주려는데 값 을 못받아오네요..
<?php
$categories = explode('|', $row['bo_category_list']);
for ($j=0; $j<count($categories); $j++) {
$category = trim($categories[$j]);
$cp = sql_fetch(" select * from g5_category_point where bo_category_name = '{$category}' and bo_table = '{$row['bo_table']}' ");
if ($category == '') continue;
?>
<tr class="<?php echo $bg; ?>">
<td colspan="5"></td>
<td style="text-align:left">카테고리: <?php echo $category ?></td>
<td class="td_numsmall">
<label for="category_read_point_<?php echo $j; ?>" class="sound_only">읽기 포인트</label>
<input type="text" name="category_read_point[<?php echo $j ?>]" value="<?php echo $cp['bo_read_point'] ?>" id="category_read_point" class="tbl_input" size="2">
</td>
<td class="td_numsmall">
<label for="category_write_point_<?php echo $j; ?>" class="sound_only">쓰기 포인트</label>
<input type="text" name="category_write_point[<?php echo $j ?>]" value="<?php echo $cp['bo_write_point'] ?>" id="category_read_point" class="tbl_input" size="2">
</td>
<td class="td_numsmall">
<label for="category_comment_point_<?php echo $j; ?>" class="sound_only">댓글 포인트</label>
<input type="text" name="category_comment_point[<?php echo $j ?>]" value="<?php echo $cp['bo_comment_point'] ?>" id="category_read_point" class="tbl_input" size="2">
</td>
<td class="td_numsmall">
<label for="category_download_point_<?php echo $j; ?>" class="sound_only">다운<br>포인트</label>
<input type="text" name="category_download_point[<?php echo $j ?>]" value="<?php echo $cp['bo_download_point'] ?>" id="category_read_point" class="tbl_input" size="2">
</td>
<td colspan="6"></td>
</tr>
<?php } ?>
원인을 찾아보니까 name 부분에서 배열처리부분에 $j 가 들어가는데 저부분인거같은데 잘 모르겠네요..
!-->답변 2
while 이나 for로 $row 값을 얻는 곳 외부 위쪽에
$category_i=0; 으로 지정해 주시고
$categories = explode('|', $row['bo_category_list']);
for ($j=0; $j<count($categories); $j++) {
$category = trim($categories[$j]);
$cp = sql_fetch(" select * from g5_category_point where bo_category_name = '{$category}' and bo_table = '{$row['bo_table']}' ");
if ($category == '') continue;
?>
<tr class="<?php echo $bg; ?>">
<td colspan="5"></td>
<td style="text-align:left">카테고리: <?php echo $category ?>
<!-- 여기추가 -->
<input type="hidden" name="cate_bo_table[<?php echo $category_i;?>]" value="<?php echo $row['bo_table'];?>">
<input type="hidden" name="bo_category_name[<?php echo $category_i;?>]" value="<?php echo $category;?>">
<!-- 여기 추가 -->
</td>
$j 를 $category_i 로 변경해 주시고 for 문 하단분에 $category_i++ 를 추가해 주십니다
<td class="td_numsmall">
<label for="category_download_point_<?php echo $category_i; ?>" class="sound_only">다운<br>포인트</label>
<input type="text" name="category_download_point[<?php echo $category_i ?>]" value="<?php echo $cp['bo_download_point'] ?>" id="category_read_point" class="tbl_input" size="2">
</td>
<td colspan="6"></td>
</tr>
<?php
//for 문안에 추가
$category_i++;
}
?>
update나 추가 부분에
<input type="hidden" name="cate_bo_table[<?php echo $category_i;?>]" value="<?php echo $row['bo_table'];?>">
<input type="hidden" name="bo_category_name[<?php echo $category_i;?>]" value="<?php echo $category;?>">
$counter = count($cate_bo_table);
for($m=0;$m<$counter;$m++)
{
$cp = sql_fetch(" select count(*) as cnt from g5_category_point where bo_category_name = '".$bo_category_name[$m]."' and bo_table = '".$cate_bo_table[$m]."' ");
if($cp[cnt]){
//내용을 업데이트 한다
$sql = "update g5_category_point set
...
where bo_category_name = '".$bo_category_name[$m]."'
and bo_table = '".$cate_bo_table[$m]."' ";
sql_query($sql);
}
else{
//내용을 등록한다
$sql = "insert into g5_category_point set
....
bo_category_name = '".$bo_category_name[$m]."',
bo_table = '".$cate_bo_table[$m]."' ";
sql_query($sql);
}
}
형식으로 처리하시면 되실듯 합니다
값을 불러오는 부분은 문제가 없어보이는데 혹시 디비에서 값을 불러오는 부분에 잘못된것이 아닌가요?
$cp = sql_fetch(" select * from g5_category_point where bo_category_name = '{$category}' and bo_table = '{$row['bo_table']}' ");
var_dump($cp);
로 값을 제대로 불러올수있는지를 체크해보셔야 할듯합니다.
!-->