제목 | foreach 문을 2번 사용 | ||
---|---|---|---|
카테고리 | CI 4 관련 | ||
글쓴이 | 황현빈 | 작성시각 | 2020/10/29 13:55:18 |
|
|||
ci 2로 개발하고 있습니다.
모델에서 db의 테이블을 조회해서 컨트롤러에서 $data['list']에 담고 뷰로 $data를 넘겨주었습니다.
뷰에서 foreach 문으로 $list를 돌면서 테이블에 출력했습니다. 정상적으로 출력이 되었는데 같은 뷰 페이지에서 한번더 foreach문으로 $list의 값을 다시 출력하니 읽지를 못하네요
foreach문에서 변수를 한번 사용하면 변수가 사라지는 건가요?
재 사용하려면 어떻게 해야되나요? |
|||
다음글 | ci 모델 쿼리 안에 where in 변수 (5) | ||
이전글 | csrf 문의 드립니다. (8) | ||
황현빈
/
2020/10/29 14:11:40 /
추천
0
|
PureAni
/
2020/10/29 14:16:24 /
추천
0
소스코드가 어떻게 되어있나요?
|
변종원(웅파)
/
2020/10/29 14:20:24 /
추천
0
소스 어딘가에서 재선언했을겁니다.
|
황현빈
/
2020/10/29 14:29:23 /
추천
0
var_dump($list);
foreach(array_reverse($list) as $key => $list) {
$balance=$balance-$list->withdraw+$list->deposit;
$bankType = $list->bankType;
if ($bankType==null){
$bankType = 'noBankType';
}
$deposit = number_format($list->deposit);
$withdraw = number_format($list->withdraw);
$balance = number_format($balance);
$requisition = number_format($list->requisition);
if ($requisition == 0){
$requisition = '';
}
if ($deposit == 0){
$deposit = '';
}
if ($withdraw == 0){
$withdraw = '';
}
// if ($balance == 0){
// $balance = '';
// }
?>
<tr class="row" name = "<?=$key?>">
<input type="hidden" style="color:red" name="idx" value="<?=$list->idx?>" />
<td class="noExl"><input type="checkbox" name="delRow"></td>
<td scope="row"><input class="input" style="width:100%; text-align:left;" type="text" name="dateOfIssue"
value="<?=$list->dateOfIssue?>" maxlength="10" onchange="modifyInput(this);"/></td>
<td scope="row"><input class="input" style="width:100%; text-align:left;" type="text" name="fixedDate"
value="<?=$list->fixedDate?>" maxlength="10" onchange="modifyInput(this);"/></td>
<td scope="row"><input class="input" style="width:100%; text-align:left;" type="text" name="dueDate"
value="<?=$list->dueDate?>" maxlength="10" onchange="modifyInput(this);"/></td>
<td scope="row">
<select id="list_select" style="width:100%; height:100%; text-align:left; border:none;" name="type" onchange="modifyInput(this);"/>
<option value=""<?if($list->type== null){?>selected<?}?>></option>
<option value="매입채무"<?if($list->type=="매입채무"){?>selected<?}?>>매입채무</option>
<option value="매출채권"<?if($list->type=="매출채권"){?>selected<?}?>>매출채권</option>
<option value="운영비용"<?if($list->type=="운영비용"){?>selected<?}?>>운영비용</option>
</select>
</td>
<td scope="row">
<select id="list_select" name="bankType" style="width:100%; height:100%; text-align:left; border:none;" onchange="modifyInput(this);">
<?php
if($list->bankType != null){
echo "123";
echo "<option value=''></option>";
for($i=0; $i<count($selectBankTypeArr); $i++){
echo "<option value='".$selectBankTypeArr[$i]."' ";
if(($list->bankType) == ($selectBankTypeArr[$i])){
echo "selected='selected'";
}
echo ">".$selectBankTypeArr[$i]."</option>";
}
}else{
echo "<option value='' selected></option>";
for($i=0; $i<count($selectBankTypeArr); $i++){
echo "<option value='".$selectBankTypeArr[$i]."' ";
echo ">".$selectBankTypeArr[$i]."</option>";
}
}
?>
</select>
</td>
<td scope="row"><input class="input" style="width:100%; text-align:left;" type="text" name="customer"
value="<?=$list->customer?>" title="<?=$list->customer?>" onchange="modifyInput(this);"/></td>
<td scope="row"><input class="input" style="width:100%; text-align:left;" type="text" name="endUser"
value="<?=$list->endUser?>" title="<?=$list->endUser?>" onchange="modifyInput(this);"/></td>
<td scope="row"><input class="input" style="width:100%; text-align:left;" type="text" name="breakdown"
value="<?=$list->breakdown?>" title="<?=$list->breakdown?>" onchange="modifyInput(this);"/></td>
<td scope="row"><input class="input" style="width:70%; text-align:right;" type="text" name="requisition"
value="<?=$requisition?>" title="<?=$requisition?>" onchange="modifyInput(this);" onFocus="deCommaStr(this);" onBlur="this.value = commaStr(this.value);" onkeyup="onlyNumber(this);" /></td>
<td scope="row"><input class="input" style="width:70%; text-align:right;" type="text" name="deposit"
class="deposit" name="money" value="<?=$deposit?>" title="<?=$deposit?>" onchange="calcBalance(); modifyInput(this);" onFocus="deCommaStr(this); oldVal(this);" onBlur="this.value = commaStr(this.value);" onkeyup="onlyNumber(this);" /></td>
<td scope="row"><input class="input" style="width:70%; text-align:right;" type="text" name="withdraw"
class="withdraw" name="money" value="<?=$withdraw?>" title="<?=$withdraw?>" onchange="calcBalance(); modifyInput(this);" onFocus="deCommaStr(this); oldVal(this);" onBlur="this.value = commaStr(this.value);" onkeyup="onlyNumber(this);"/></td>
<td scope="row"><input class="input" style="width:70%; text-align:right;" type="text" name="balance"
class="balance" name="money" value="<?=$balance?>" title="<?=$balance?>" onFocus="deCommaStr(this);" onBlur="this.value = commaStr(this.value);" readonly/></td>
<td scope="row"><input class="input" style="width:70%; text-align:right;" type="text" name="balance2"
class="balance2" name="money" value="<?=$balance?>" title="<?=$balance?>" onFocus="deCommaStr(this);" onBlur="this.value = commaStr(this.value);" readonly/></td>
</tr>
</tr>
<?php
$deposit = filter_var($deposit, 519);
$withdraw = filter_var($withdraw, 519);
$balance = filter_var($balance, 519);
$requisition = filter_var($requisition, 519);
}
echo "--------------------";
var_dump($list);
?>
|
PureAni
/
2020/10/29 14:35:57 /
추천
0
2번째줄에.. foreach(array_reverse($list) as $key => $list) { 라고 되어있네요. |
$list를 var_dump를 찍었을때 array(100)이 출력되고 foreach문이 끝나고 다시 var_dump를 찍으니 object(stdClass)#43 이렇게 출력되네요