테스트 사이트 - 개발 중인 베타 버전입니다

최신글 case 띄우는법 질문합니다.

최현태 6년 전 조회 2,611

안녕하세요 php 초보입니다...

다름이 아니라 

 

case별 값을 띄우고 싶습니다

 

switch($list[$i]['sell_state']){

                    case 1:

                        $sell_state = '<font color="red"><strong>결제대기</strong></font>';

                        break;

                    case 2:

                        $sell_state = '<font color="green"><strong>결제완료</strong></font>';

                        break;

                    case 3:

                        $sell_state = '<font color="gray"><strong>결제실패</strong></font>';

                        break;

                    default:

                        $sell_state = '<font color="red"><strong>결제대기</strong></font>';

                        break;

                }

 

이부분 게시판스킨 list.skin.php 에 들어갑니다.

 

문제는 최신글에서도 결과를 띄우고싶은데요

 

<td class="td_name"><?php echo $list[$i]['wr_1'] ?></td> 같은경우는

 

latest.skin.php 에 

 

<span style="color:red;">결과:<?php echo $list[$i]['wr_1'] ?></span>

 

이런식으로 하면 띄워집니다만...

 

위의 case?는 

 

<?php echo $list[$i]['sell_state'] ?>

이렇게 하니 1만 뜹니다. 

 

어떻게하면 최신글에서 결과를 띄울 수 있을까요?

댓글을 작성하려면 로그인이 필요합니다.

답변 2개

case문이 들어갔다면 $list[$i]['sell_state'] 대신 $sell_state을 출력해야죠

로그인 후 평가할 수 있습니다

답변에 대한 댓글 3개

최현태
6년 전
그렇게하면 게시판의 결과값이 안나오고 숫자 1만 나옵니다..
최현태
6년 전
$sell_state 또한 여러방식?으로 해보았지만

게시판의 결과값이랑 상관없으 1 또는 case1의 결과값만 나옵니다
홀리스톤
6년 전
$sell_state의 결과값이 1이 나올수 없습니다.
case문이 작동하지 않은 걸로 보여집니다.

댓글을 작성하려면 로그인이 필요합니다.

유찬아빠

최신글도 루프 안에 동일하게  switch 구문 넣으시고

 

표현할 자리에 <?php echo $sell_state?> 하시면 됩니다

for(.................){

switch($list[$i]['sell_state']){
                    case 1:
                        $sell_state = '<font color="red"><strong>결제대기</strong></font>';
                        break;
                    case 2:
                        $sell_state = '<font color="green"><strong>결제완료</strong></font>';
                        break;
                    case 3:
                        $sell_state = '<font color="gray"><strong>결제실패</strong></font>';
                        break;
                    default:
                        $sell_state = '<font color="red"><strong>결제대기</strong></font>';
                        break;
                }

 

<?php echo $sell_state?>

 

}

로그인 후 평가할 수 있습니다

답변에 대한 댓글 4개

최현태
6년 전
안됩니다...ㅜ 소스그대로 뜹니다..
유찬아빠
6년 전
적용한 소스를 올려보세요
최현태
6년 전
[code] switch($list[$i]['sell_state']){
case 1:
$sell_state = '<font color="red"><strong>결제대기</strong></font>';
break;
case 2:
$sell_state = '<font color="green"><strong>결제완료</strong></font>';
break;
case 3:
$sell_state = '<font color="gray"><strong>결제실패</strong></font>';
break;
default:
$sell_state = '<font color="red"><strong>결제대기</strong></font>';
break;
}

<?php for ($i=0; $i<count($list); $i++) { ?>
</script>

<li>
<?php echo $sell_state?>
<span style="color:red;"><strong>아이템:<?php echo $list[$i]['wr_1'] ?></strong></span>[/code]
유찬아빠
6년 전
switch($list[$i]['sell_state']){
case 1:
$sell_state = '<font color="red"><strong>결제대기</strong></font>';
break;
case 2:
$sell_state = '<font color="green"><strong>결제완료</strong></font>';
break;
case 3:
$sell_state = '<font color="gray"><strong>결제실패</strong></font>';
break;
default:
$sell_state = '<font color="red"><strong>결제대기</strong></font>';
break;
}

<?php for ($i=0; $i<count($list); $i++) { ?>
</script>

<li>
<?php echo $sell_state?>
<span style="color:red;"><strong>아이템:<?php echo $list[$i]['wr_1'] ?></strong></span>

답변이 늦었네요....

<?php for ($i=0; $i<count($list); $i++) { ?>
</script> ---> 이건 뭐죠?


정리하자면
케이스 구문은 분명 for 루프 안에 들어가야 합니다.

[code]
<?php for ($i=0; $i<count($list); $i++) {

switch($list[$i]['sell_state']){
case 1:
$sell_state = '<font color="red"><strong>결제대기</strong></font>';
break;
case 2:
$sell_state = '<font color="green"><strong>결제완료</strong></font>';
break;
case 3:
$sell_state = '<font color="gray"><strong>결제실패</strong></font>';
break;
default:
$sell_state = '<font color="red"><strong>결제대기</strong></font>';
break;
}

?>


<li>
<?php echo $sell_state?>
<span style="color:red;"><strong>아이템:<?php echo $list[$i]['wr_1'] ?></strong></span>
[/code]

이런식으로요

댓글을 작성하려면 로그인이 필요합니다.

답변을 작성하려면 로그인이 필요합니다.

로그인