php 1~12월 내용나오게 하려면 어떻게 해야 할까요?

php 1~12월 내용나오게 하려면 어떻게 해야 할까요?

QA

php 1~12월 내용나오게 하려면 어떻게 해야 할까요?

본문

안녕하세요 도움좀 얻고자 합니다.

 

1~12월을 입력받아

if($wr_1_1) $wr_1=$wr_1_1."|";
if($wr_1_2) $wr_1.=$wr_1_2."|";
if($wr_1_3) $wr_1.=$wr_1_3."|";
if($wr_1_4) $wr_1.=$wr_1_4."|";
if($wr_1_5) $wr_1.=$wr_1_5."|";
if($wr_1_6) $wr_1.=$wr_1_6."|";
if($wr_1_7) $wr_1.=$wr_1_7."|";
if($wr_1_8) $wr_1.=$wr_1_8."|";
if($wr_1_9) $wr_1.=$wr_1_9."|";
if($wr_1_10) $wr_1.=$wr_1_10."|";
if($wr_1_11) $wr_1.=$wr_1_11."|";
if($wr_1_12) $wr_1.=$wr_1_12."|";

 

$wr_1 = march|april||may|june;

 

리스트 페이지에서 $wr_1 변수를 $wr_1 = explode("|", $wr_1);

 

배열로 나누어서 $wr_1[0] = march; 결과값은 이건데

 

1월에 매칭하려면 밸류값은  $wr_1[0] = march 이므로 이부분을

 

1~12월에 어떻게 매칭을 하면 될까요 많은 도움 부탁드립니다.

 

 


 
 
<table>
<caption>과정</caption>
 <tr>
   <th>프로그램 제목</th>
   <td>1월</td>
   <td>2월</td>
   <td>3월</td>
   <td>4월</td>
   <td>5월</td>
   <td>6월</td>
   <td>7월</td>
   <td>8월</td>
   <td>9월</td> 
   <td>10월</td>
   <td>11월</td>
   <td>12월</td>
 </tr>
<?php
    for ($i=0; $i<count($list); $i++) {
           $wr_1 = explode("|", $wr_1);
?>
 <tr>
  <th><?php echo $list[$i]['subject'] ?></th>
  <td><?php if($wr_1 == "january") echo  cut_str(strip_tags($list[$i]['content']),100)?> </td>
  <td><?php if($wr_1 == "february") echo  cut_str(strip_tags($list[$i]['content']),100)?></td>
  <td><?php if($wr_1 == "march") echo  cut_str(strip_tags($list[$i]['content']),100)?></td>
  <td><?php if($wr_1 == "april") echo  cut_str(strip_tags($list[$i]['content']),100)?></td>
  <td class="bg_red"><?php if($wr_1 == "may") echo  cut_str(strip_tags($list[$i]['content']),100)?></td>
  <td><?php if($wr_1 == "june") echo  cut_str(strip_tags($list[$i]['content']),100)?></td>
  <td><?php if($wr_1 == "july") echo  cut_str(strip_tags($list[$i]['content']),100)?></td>
  <td><?php if($wr_1 == "august") echo  cut_str(strip_tags($list[$i]['content']),100)?></td>
  <td><?php if($wr_1 == "september") echo  cut_str(strip_tags($list[$i]['content']),100)?></td>
  <td><?php if($wr_1 == "october") echo  cut_str(strip_tags($list[$i]['content']),100)?></td>
  <td><?php if($wr_1 == "november") echo  cut_str(strip_tags($list[$i]['content']),100)?></td>
  <td><?php if($wr_1 == "december") echo  cut_str(strip_tags($list[$i]['content']),100)?></td>
 </tr>
    <?php } ?>
    <?php if (count($list) == 0) { echo '<tr><td colspan="'.$colspan.'" class="empty_table">게시물이 없습니다.</td></tr>'; } ?>
</table>

이 질문에 댓글 쓰기 :

답변 3


<tr>
    <th><?php echo $list[$i]['subject'] ?></th>
    <?php
    $wr1 = explode("|", $wr_1);
    $months = array("january", "february", "march");
    foreach($months as $v) {
        echo "<td>";
        echo in_array($v, $wr1) ? cut_str(strip_tags($list[$i]['content']), 100) : "";
        echo "</td>";
    }
    ?>
</tr>

$months = array("january", "february", "march");

여기는 뒤에 4월부터 채워 넣으세요. 너무 길어져서 안 넣었습니다.

제가 원하는 결과는





$wr_1 = march|april||may|june;





1월    2월    3월    4월    5월    6월    7월    8월    9월    10월    11월    12월


                  내용1    내용1  내용1  내용1





이런식으로 표현이 가능할까요???


<?php
$months = array("january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december");
if(sizeof($list) > 0) {
	for($i=0; $i<sizeof($list); $i++) {
		$wr1 = explode("|", $list[$i]['wr_1']);
		echo "<tr>";
		echo "<th>".$list[$i]['wr_subject']."</th>";
		foreach($months as $v) {
			echo "<td>";
			echo in_array($v, $wr1) ? cut_str(strip_tags($list[$i]['wr_content']), 100) : "";
			echo "</td>";
		}
		echo "</tr>";
	}
} else {
	echo "<tr><td colspan='12' class='empty_table'>게시물이 없습니다.</td></tr>";
}
?>

질문 내용이 너무 모호해서 답변하시는 분들이 전부 몇 번씩 답을 해야 합니다.
이런 경우는 처음부터 어떤 형식을 원하신다고 남기시는 게 훨씬 빠른 답변이 나올 겁니다.

$list[$i]['wr_1']에 있는 월에 맞는

<td>에 $list[$i]['content']를 뿌려준다.

(content <--이게 맞나 확인도 필요합니다.

아니라면 $list[$i]['wr_content'] 입니다.)

제가 이해한게 맞다면, 이렇게 하면 됩니다.


<table>
 <caption>과정</caption>
 <tr>
 <th>프로그램 제목</th>
 <?php
 for ($j=1; $j<=12; $j++) {
  echo "<td>".$j."월</td>";
 }
 ?>
 </tr>
 <?php
 for ($i=0; $i<count($list); $i++) {
 ?>
 <tr>
 <th><?php echo $list[$i]['subject'] ?></th>
 <?php
 $month_arr = array("january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december");
 for ($j=0; $j<count($month_arr); $j++) {
  echo "<td>";
  if (strpos($list[$i]['wr_1'], $month_arr[$j]) !== false){
   echo cut_str(strip_tags($list[$i]['content']),100);
  }
  echo "</td>";
 }
 ?>
 </tr>
 <?php } ?>
 <?php if (count($list) == 0) { echo '<tr><td colspan="'.$colspan.'" class="empty_table">게시물이 없습니다.</td></tr>'; } ?>
</table>

제가 원하는 결과는





$wr_1 = march|april||may|june;





1월    2월    3월    4월    5월    6월    7월    8월    9월    10월    11월    12월


                  내용1    내용1  내용1  내용1





이런식으로 표현이 가능할까요???

제가 만들어드린게 그 내용입니다.
위 소스는 $list[$i]['wr_1'] 이걸로 했고
$wr_1 이걸로 변경했습니다.


<table>
<caption>과정</caption>
<tr>
	<th>프로그램 제목</th>
	<?php
	for ($j=1; $j<=12; $j++) {
	echo "<td>".$j."월</td>";
	}
	?>
	</tr>
	<?php
	for ($i=0; $i<count($list); $i++) {
	?>
<tr>
	<th><?php echo $list[$i]['subject'] ?></th>
	<?php
	$month_arr = array("january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december");
	for ($j=0; $j<count($month_arr); $j++) {
	echo "<td>";
	if (strpos($wr_1, $month_arr[$j]) !== false){
	echo cut_str(strip_tags($list[$i]['content']),100);
	}
	echo "</td>";
	}
	?>
</tr>
<?php } ?>
<?php if (count($list) == 0) { echo '<tr><td colspan="'.$colspan.'" class="empty_table">게시물이 없습니다.</td></tr>'; } ?>
</table>

제 소스 그대로 붙여서 사용하시면 됩니다. 테스트했구요.

list.skin.php 에서 작업하신다면,
$wr_1 이게 아니라,  $list[$i]['wr_1']  이거일거 같구요.
$list[$i]['content'] 이게 아니라,  $list[$i]['wr_content']  이거일거 같구요.

이런경우에는

 

배열을 가지고 월의 이름에 따른 배열을 선언합니다.

 

 
$monkind = array("january", "february", .........., "december");

 

그리과 작성하신 위의 로직에서 문법이 틀린부분은

if($wr_1 == "january") 

 

이 문장과 동일한 구문은 전부 오류가 납니다.

 

왜냐면

 

$wr_1 = explode("|", $wr_1);

 

이렇게 작성한 내용에 따라서, 

결과값은 

$wr_1 은 배열로 구성됩니다. 몇개가 존재할지는 모릅니다만

 

원하시는 형태는

1월~12월까지 가로로 나열되고

각 월에 값이 있으면 해당 Row의 정보를 보이게 하고 싶은신것 같습니다.

 

for문 이하만 변경해서 작성해봅니다.

 


$monkind = array("january", "february", .........., "december");  // 내용은 직접채우세요
for ($i=0; $i<count($list); $i++) {
    $list_wr1 = explode("|", $wr_1);    //이름이 중첩되지 않게 합니다.
    ?>
 <tr>
 
  <th><?php echo $list[$i]['subject'] ?></th>\
  <?php
  
    for ($j = 0; $j < count($monkind); $j++ ) {?>
  <td><?php if($list_wr1[$monkind[$j]) echo  cut_str(strip_tags($list[$i]['content']),100)?> </td>
    <?php 
    } ?>
 </tr>
    <?php } ?>
    <?php if (count($list) == 0) { echo '<tr><td colspan="'.$colspan.'" class="empty_table">게시물이 없습니다.</td></tr>'; } ?>
</table>

 

이렇게 변경해보세요

 

 

답변을 작성하시기 전에 로그인 해주세요.
전체 6
QA 내용 검색

회원로그인

(주)에스아이알소프트 / 대표:홍석명 / (06211) 서울특별시 강남구 역삼동 707-34 한신인터밸리24 서관 1404호 / E-Mail: admin@sir.kr
사업자등록번호: 217-81-36347 / 통신판매업신고번호:2014-서울강남-02098호 / 개인정보보호책임자:김민섭(minsup@sir.kr)
© SIRSOFT