개발 Q&A

제목 안녕하세요 첫질문글 올립니다.
카테고리 PHP
글쓴이 경이 작성시각 2021/09/29 11:19:49
댓글 : 9 추천 : 0 스크랩 : 0 조회수 : 5530   RSS
//뷰부분
<?php

foreach ($posting as $detail) {
    if ($detail->posting_type == 0) {
        ?>
<tr class="tr">
            <input  type="hidden" name="posting_type" value="0">
            <td><input  type="hidden" name="report_day" value="<?=$detail->report_day?>"><?=$detail->report_day?>일</td>
            <td><input  type="hidden" name="hospital_id" value="<?=$detail->hospital_id?>"><?=$detail->hosp_name?></td>
            <td><input  type="hidden" name="last_month" value="<?=$detail->last_month?>"><?=$detail->last_month?>개</td>
            <td><input  type="hidden" name="total" value="<?=$detail->total?>"><?=$detail->total?>개</td>
             <?     for($i=0;$i<$maxDay;$i++){     ?>
             <td><?php echo $daily[$i]; ?>
             </td>
            <?        }            ?>
            <td><?=$detail->last_month?>개</td>
        </tr>
<?php
    } //if
} //foreach
?>



//컨트롤러부분
$posting_data = array(
                                'report_day' => $this->input->post('report_day'),
                                'last_month' => $this->input->post('last_month'),
                            //    'posting_user_id' => $this->input->post('posting_user_id'),
                                'total' => $this->input->post('total'),
                                'posting_type' => $this->input->post('posting_type'),
                                'hospital_id' => $this->input->post('hospital_id'),
                            //    'posting_day' => $this->input->post('posting_day'),
                            ); 

 

 

위와 같이 코딩을 했는데 값이 넘어왔다가 안넘어왔다하다가 현재는 print_r($posting_data);로 값을 확인해도 아무것도 확인이 되지 않습니다.... 도대체 무슨 문제일까요....? 지금 이틀째 확인해보고 있는데 전혀 알수가 없어서요,,, 도움주시면 감사합니다..

 다음글 안녕하세요, 초보 개발자입니다. 도움이 필요합니다!ㅠㅠ
 이전글 spring에 pebble java 설정 도와주세요ㅠㅠ (3)

댓글

한대승(불의회상) / 2021/09/29 11:22:38 / 추천 0

위 내용으론 전후 파악이 안되네요.

도움드리기 참 난감하네요.

경이 / 2021/09/29 11:26:13 / 추천 0

한대승님 안녕하세요. 음,,, 제가 설명이 부족했나봐요

우선 뷰에서 컨트롤러로 데이터를 넘기고 싶은데 제 생각엔 맞게 작성했다고 느껴지는데 이 부분이 지금 되질 않습니다..

(웃긴게 그전에는 또 되다가 갑자기 또 되질 않습니다...)

혹시 어느 부분에서 문제일까요..?

테러보이 / 2021/09/29 11:39:30 / 추천 0
컨트롤러 소스 뷰까지보여주세요
변종원(웅파) / 2021/09/29 11:44:38 / 추천 0

컨트롤러에서 연관배열로 값을 만들었고 뷰에서는 객체배열로 사용했습니다 $detail->posting_type



그리고 컨트롤러에서 $posting_data 로 배열을 만들고 뷰에서는 $posting로 사용했습니다. 어떻게 넘겼는지 컨트롤러 소스 필요.

경이 / 2021/09/30 10:48:33 / 추천 0
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Posting_plan extends  Both_Controller {
	
    function __construct() {
        parent::__construct();
		
		$this->load->model("posting_models");
    }

	public function index()
{	
		
if (empty($_GET['date'])) { // 입력값이 없으면 오늘을 기준으로 한다
    $thisDay = date("Y-m-d");
} else {
    if (isset($_GET['btn'])) {
        if ($_GET['btn'] == 'prev') { // 이전달 구하기
            $thisDay = date("Y-m-d", strtotime($_GET['date'] . " -1 month"));
        } elseif ($_GET['btn'] == 'next') { // 다음달 구하기
            $thisDay = date("Y-m-d", strtotime($_GET['date'] . " +1 month"));
        }
    } else {
        $thisDay = $_GET['date']; // 입력한 날짜 가져오기
    }
}

$thisDayArry = explode('-', $thisDay);
$thisY = $thisDayArry[0];
$thisM = $thisDayArry[1];
$thisD = $thisDayArry[2];

$maxDay = date("t", strtotime($thisDay)); // 총일수

$startWeek = date("w", strtotime($thisY . "-" . $thisM . "-01")); // 1일의 요일 구하기
$maxWeek = ceil(($maxDay + $startWeek) / 7); // 총주수


for($t=0;$t<2;$t++){ 
	$arr[] = array();
	 for($i=0; $i<5; $i++){
	   $arr[$i] = rand(1, $maxDay);
														 $nalja9 = "$thisY-$thisM-$arr[$i]";
														$yoeil = date('w' , strtotime($nalja9) );

													if($yoeil==0||$yoeil==6){
													//	print_r('   주말                '); 
														$i--;
														continue;
														}

	   for($j=0; $j<$i; $j++)
	   {
		 if($arr[$i] == $arr[$j])
		 {
		   $i--;
		   break;
		 }
	   }  
	 }
	sort($arr);
//array_push($arr,$arr[$t]);

	//print_r($arr);



$result=array();
				for($day=1; $day<=$maxDay;$day++){  
						 if(in_array($day, $arr)){
							array_push($result, "1");
						  } else {
							array_push($result, "0");
						  }
				}
					print_r($result);
}

//	print_r($result);
$posting_data = array(
                                'report_day' => $this->input->post('report_day'),
                                'last_month' => $this->input->post('last_month'),
                                'posting_user_id' => $this->input->post('posting_user_id'),
                                'total' => $this->input->post('total'),
                                'posting_type' => $this->input->post('posting_type'),
                                'hospital_id' => $this->input->post('hospital_id'),
                                'posting_day' => $this->input->post('posting_day'),
                            ); 


$posting_user_id= $this->input->post('select', true);

//print_r($this->input->post(null, true));
	$data['daily'] = $result;
	$data['posting'] = $this->posting_models->get_manage_hospital_list(184);
	$data['marketer_list'] = $this->posting_models->get_employees_active_team_list(1);		// 마케팅팀 직원 리스트
	//$this->posting_models-> save_posting( $posting_data );
//	print_r($posting_data);
	 $this->load->view('posting',$data);
	  }	

}

여기가 컨트롤러 소스입니다.

경이 / 2021/09/30 10:49:35 / 추천 0
<style>
table, th, td {
	border: 1px solid #444444;
}

#detail,#naver_detail {
	margin-left: auto;
	margin-right: auto;
	width: 1200px;
}
</style>
<?php
if (empty($_GET['date'])) { // 입력값이 없으면 오늘을 기준으로 한다
    $thisDay = date("Y-m-d");
} else {
    if (isset($_GET['btn'])) {
        if ($_GET['btn'] == 'prev') { // 이전달 구하기
            $thisDay = date("Y-m-d", strtotime($_GET['date'] . " -1 month"));
        } elseif ($_GET['btn'] == 'next') { // 다음달 구하기
            $thisDay = date("Y-m-d", strtotime($_GET['date'] . " +1 month"));
        }
    } else {
        $thisDay = $_GET['date']; // 입력한 날짜 가져오기
    }
}

$thisDayArry = explode('-', $thisDay);
$thisY = $thisDayArry[0];
$thisM = $thisDayArry[1];
$thisD = $thisDayArry[2];

$maxDay = date("t", strtotime($thisDay)); // 총일수

$startWeek = date("w", strtotime($thisY . "-" . $thisM . "-01")); // 1일의 요일 구하기
$maxWeek = ceil(($maxDay + $startWeek) / 7); // 총주수
$endWeek = date("w", strtotime($thisY . "-" . $thisM . "-" . $maxDay)); // 마지막일은 무슨 요일인가

?>

 <select id="select" style="height: 40px;"> 
<?php foreach($marketer_list as $marketer){ ?>
			<option  value="<?=$marketer->id?>"><?=$marketer->username?></option> 
			<?php   } ?> 
</select> <input type="submit"  id="choice" value="선택" /> 

<br>
<br>
<br>

	<a href="posting_plan?date=<?php echo $thisDay?>&btn=prev">이전달</a> <a
		href="posting_plan?date<?php echo "  " . $thisY . '년 ' . $thisM . '월 ' . "  "; ?>">
<?php echo "  " . $thisY . '년 ' . $thisM . '월 ' . "  "; ?></a>
	<a href="posting_plan?date=<?php echo $thisDay?>&btn=next">다음달</a>


<!-- 그냥 달력 -->
<table style="width: 500px; height: 200px;">

		<tr>
			<th>일</th>
			<th>월</th>
			<th>화</th>
			<th>수</th>
			<th>목</th>
			<th>금</th>
			<th>토</th>
		</tr>

	<tbody>
<?php $day=1; ?>
<?php for($i=1; $i<=$maxWeek; $i++){ //세로칸?>
<tr>
<?php for($j=0; $j<7; $j++){ //가로칸?>
<td>
<?php
        if (($i == 1 && $j < $startWeek) || ($i == $maxWeek && $j > $endWeek)) {
            // 첫째 주이고 j가 1일의 요일보다 작은 경우 패스 || 마지막 주 이고 j가 마지막일의 요일보다 크면 패스
            echo '';
        } else {
            if ($j == 0) {
                echo "<font color=red>";
                echo $day;
                echo "</font>";
            } else if ($j == 6) {
                echo "<font color=blue>";
                echo $day;
                echo "</font>";
            } else {
                echo "<font color=black>";
                echo $day;
                echo "</font>";
            }
            $day ++;
        }
        ?>
</td>
<?php } ?>
</tr>
<?php } ?>
</tbody>
</table>
<br>

<div class="show_posting" style="display:show"> 

<form method="post" name="form">
<!-- 카페/블로그 포스팅 관련 -->
<table id="detail" class="postingall">
	<thead>
		<tr class="tr">
			<th class="th">날짜</th>
			<th class="th">포스팅</th>
			<th class="th">이전개수</th>
			<th class="th" id="total">총개수</th>
<?php  for($day=1; $day<=$maxDay;$day++){  ?>
			<th class="th" id="day1"><?php  echo $day;   } ?></th>
			<th class="th">개수체크</th>
		</tr>
	</thead>
	<tbody>

<?php

foreach ($posting as $detail) {
    if ($detail->posting_type == 0) {
        ?>
<tr class="tr">
            <input  type="hidden" name="posting_type[]" value="0">
            <td><input  type="hidden" name="report_day[]" value="<?=$detail->report_day?>"><?=$detail->report_day?>일</td>
            <td><input  type="hidden" name="hospital_id[]" value="<?=$detail->hospital_id?>"><?=$detail->hosp_name?></td>
            <td><input  type="hidden" name="last_month[]" value="<?=$detail->last_month?>"><?=$detail->last_month?>개</td>
            <td><input  type="hidden" name="total[]" value="<?=$detail->total?>"><?=$detail->total?>개</td>
        <!--     <?	for($i=0;$i<$maxDay;$i++){     ?> -->
            <!--   <td><?php echo $daily[$i]; ?> </td>  -->
          <!--   <?        }   ?> -->
	<?php $day=1; 

//주말제외하고 랜덤으로 날짜뽑기
if($detail->report_day==1){
	$arr = array();

	 for($i=0; $i<$detail->total; $i++)
	 {
	   $arr[$i] = rand(1, $maxDay);
														 $nalja3 = "$thisY-$thisM-$arr[$i]";
														$yoeil = date('w' , strtotime($nalja3) );

													if($yoeil==0||$yoeil==6){
													//	print_r('   주말                '); 
														$i--;
														continue;
														}

	   for($j=0; $j<$i; $j++)
	   {
		 if($arr[$i] == $arr[$j])
		 {
		   $i--;
		   break;
		 }
	   }  
	 }
	sort($arr);

}else if($detail->report_day==11){
	$befor10 = array();

	 for($i=0; $i<$detail->total; $i++)
	 {
		 	   $befor10 [$i] = rand(1, 10);
	   											 $nalja4 = "$thisY-$thisM-$befor10[$i]";
														$yoeil = date('w' , strtotime($nalja4) );
													if($yoeil==0||$yoeil==6){
													//	print_r('   주말                '); 
														$i--;
														continue;
														}

	   for($j=0; $j<$i; $j++)
	   {
		 if($befor10[$i] == $befor10[$j])
		 {
		   $i--;
		   break;
		 }
	   }  
	 }
	$after11 = array();

	 for($i=0; $i<$detail->last_month; $i++)
	 {
	   $after11[$i] = rand(11, $maxDay);
														 $nalja5 = "$thisY-$thisM-$after11[$i]";
														$yoeil = date('w' , strtotime($nalja5) );
													if($yoeil==0||$yoeil==6){
													//	print_r('   주말                '); 
														$i--;
														continue;
														}

	   for($j=0; $j<$i; $j++)
	   {
		 if($after11[$i] == $after11[$j])
		 {
		   $i--;
		   break;
		 }
	   }  
	 }

	$arr= array_merge($befor10,$after11 );
	sort($arr);
}else{
	$befor20 = array();

	 for($i=0; $i<$detail->total; $i++)
	 {
		 	   $befor20 [$i] = rand(1, 20);
	   											 $nalja5 = "$thisY-$thisM-$befor20[$i]";
														$yoeil = date('w' , strtotime($nalja5) );
													if($yoeil==0||$yoeil==6){
													//	print_r('   주말                '); 
														$i--;
														continue;
														}

	   for($j=0; $j<$i; $j++)
	   {
		 if($befor20[$i] == $befor20[$j])
		 {
		   $i--;
		   break;
		 }
	   }  
	 }
	$after21 = array();

	 for($i=0; $i<$detail->last_month; $i++)
	 {
	   $after21[$i] = rand(21, $maxDay);
														 $nalja6 = "$thisY-$thisM-$after21[$i]";
														$yoeil = date('w' , strtotime($nalja6) );
													if($yoeil==0||$yoeil==6){
													//	print_r('   주말                '); 
														$i--;
														continue;
														}

	   for($j=0; $j<$i; $j++)
	   {
		 if($after21[$i] == $after21[$j])
		 {
		   $i--;
		   break;
		 }
	   }  
	 }

	$arr= array_merge($befor20,$after21 );
	sort($arr);

																	//		echo '<script>';
																	//		echo 'console.log("'.$nalja6.'")'; 
																	//		echo '</script>';



}

				for($day=1; $day<=$maxDay;$day++){  ?>
					<td> <?
						 if(in_array($day, $arr)){
							echo "1";
						  } else {
							  ?>
							<span  style="display:none;">
							<? echo "0"; ?></span>
<?
						  }
				?>
					</td>	
				<?php

				 } // for($day=1; $day<=$maxDay;$day++){
				?>		


				<td><?=$detail->last_month?>개</td>

			</tr>
<?php
    } //if
} //foreach
?>
</tbody>

</table>
<br>
<br>
<!-- 지식인 포스팅 -->
<table id="naver_detail" class="postingall">
	<thead>
		<tr class="tr">
			<th class="th">날짜</th>
			<th class="th">지식인</th>
			<th class="th">이전개수</th>
			<th class="th">총개수</th>
<?php for($day=1; $day<=$maxDay;$day++){ ?>
			<th class="th" id="day"><?php  echo $day;  } ?></th>
			<th class="th">개수체크</th>
		</tr>
	</thead>
	<tbody>




<?php
foreach ($posting as $detail) {
    if ($detail->posting_type == 1) {
        ?>
<tr class="tr">
            
            <td><?=$detail->report_day?>일</td>
            <td><?=$detail->hosp_name?></td>
            <td><?=$detail->last_month?>개</td>
            <td><?=$detail->total?>개</td>
			<?php $day=1; 

//주말제외하고 랜덤으로 날짜뽑기
if($detail->report_day==1){
	$arr = array();

	 for($i=0; $i<$detail->total; $i++)
	 {
	   $arr[$i] = rand(1, $maxDay);
														 $nalja3 = "$thisY-$thisM-$arr[$i]";
														$yoeil = date('w' , strtotime($nalja3) );

													if($yoeil==0||$yoeil==6){
													//	print_r('   주말                '); 
														$i--;
														continue;
														}

	   for($j=0; $j<$i; $j++)
	   {
		 if($arr[$i] == $arr[$j])
		 {
		   $i--;
		   break;
		 }
	   }  
	 }
	sort($arr);

}else if($detail->report_day==11){
	$befor10 = array();

	 for($i=0; $i<$detail->total; $i++)
	 {
		 	   $befor10 [$i] = rand(1, 10);
	   											 $nalja4 = "$thisY-$thisM-$befor10[$i]";
														$yoeil = date('w' , strtotime($nalja4) );
													if($yoeil==0||$yoeil==6){
													//	print_r('   주말                '); 
														$i--;
														continue;
														}

	   for($j=0; $j<$i; $j++)
	   {
		 if($befor10[$i] == $befor10[$j])
		 {
		   $i--;
		   break;
		 }
	   }  
	 }
	$after11 = array();

	 for($i=0; $i<$detail->last_month; $i++)
	 {
	   $after11[$i] = rand(11, $maxDay);
														 $nalja5 = "$thisY-$thisM-$after11[$i]";
														$yoeil = date('w' , strtotime($nalja5) );
													if($yoeil==0||$yoeil==6){
													//	print_r('   주말                '); 
														$i--;
														continue;
														}

	   for($j=0; $j<$i; $j++)
	   {
		 if($after11[$i] == $after11[$j])
		 {
		   $i--;
		   break;
		 }
	   }  
	 }

	$arr= array_merge($befor10,$after11 );
	sort($arr);
}else{
	$befor20 = array();

	 for($i=0; $i<$detail->total; $i++)
	 {
		 	   $befor20 [$i] = rand(1, 20);
	   											 $nalja5 = "$thisY-$thisM-$befor20[$i]";
														$yoeil = date('w' , strtotime($nalja5) );
													if($yoeil==0||$yoeil==6){
													//	print_r('   주말                '); 
														$i--;
														continue;
														}

	   for($j=0; $j<$i; $j++)
	   {
		 if($befor20[$i] == $befor20[$j])
		 {
		   $i--;
		   break;
		 }
	   }  
	 }
	$after21 = array();

	 for($i=0; $i<$detail->last_month; $i++)
	 {
	   $after21[$i] = rand(21, $maxDay);
														 $nalja6 = "$thisY-$thisM-$after21[$i]";
														$yoeil = date('w' , strtotime($nalja6) );
													if($yoeil==0||$yoeil==6){
													//	print_r('   주말                '); 
														$i--;
														continue;
														}

	   for($j=0; $j<$i; $j++)
	   {
		 if($after21[$i] == $after21[$j])
		 {
		   $i--;
		   break;
		 }
	   }  
	 }

	$arr= array_merge($befor20,$after21 );
	sort($arr);

																	//		echo '<script>';
																	//		echo 'console.log("'.$nalja6.'")'; 
																	//		echo '</script>';



}

				for($day=1; $day<=$maxDay;$day++){  ?>
					<td> <?
						 if(in_array($day, $arr)){
							echo "1";
						  } else {
							  ?>
							<span  style="display:none;">
							<? echo "0"; ?></span>
<?
						  }
				?>
					</td>	
				<?php

				 } // for($day=1; $day<=$maxDay;$day++){
				?>		


				<td><?=$detail->last_month?>개</td>

			</tr>
	<?php
	} //if (posting_type
	} //foreach
	?>
	<tr id="totalRow"></tr> 
</tbody>

</table>
</form>
<table id="chk_sum">
<tfoot>
            <tr>

                <td>total</td>
                <td>total</td>
                <td>total</td>
                <td>total</td>
				<?php for($day=1; $day<=$maxDay;$day++){ ?>
			<td id="total_Day"><?  } ?></td>
            </tr>
</tfoot>
</table>

</div> 




<table>
	<thead>

		<tr class="tr">

<?php  for($day=1; $day<=30;$day++){  ?>

			<th class="th" id="day1"><?php  echo $day;   } ?></th>

		</tr>
	</thead>
				<?	for($i=0;$i<2;$i++){     ?>
		 <?	foreach($daily as $value){     ?> 
          <td><?php echo $value[$i]; ?> </td>  
           <?        }   ?> 
           <?        }   ?> 
</table>






<style>
#chk_sum{ 	margin-left: 460px;
	width: 750px;}
#day,#day1,#total_Day{width:20px;}
</style>
<script>

//주말수 구하기

	var date1 = new Date('<?=$thisY?>','<?=$thisM?>'-1,1);
	var date2 = new Date('<?=$thisY?>','<?=$thisM?>'-1,'<?=$maxDay?>');
	var count =0;
	console.log(date1);
	console.log(date2);
	while(true) {  


    var temp_date = date1;
    if(temp_date.getTime() > date2.getTime()) {
        console.log("count : " + count);
        break;
    } else {
        var tmp = temp_date.getDay();
			if(tmp == 0 || tmp == 6) {
				// 주말     
			} else {
				// 평일
				count++;    
			}
        temp_date.setDate(date1.getDate() + 1); 
		}
	}
//개수 총합 구하기
var total=0;
var lastTotal=0;
$('.postingall tr').each(function() { 
$(this).find('td:eq(3)').each(function() { 
total += parseFloat($(this).text());
})
$(this).find('td:eq(2)').each(function() { 
lastTotal += parseFloat($(this).text());
})
});
        console.log("total : " + total);
		console.log("lastTotal : " + lastTotal);
		var sum = total + lastTotal;
		console.log("sum : " + sum);
		var avg= sum/count;
		var avg1 = Math.ceil(avg);
		console.log("avg1 : " +avg1);

//하루에 몇개하는지 총합


		  $(document).ready(function() {
            $('.th').each(function(i) {
                calculateColumn(i);
            });
        });

        function calculateColumn(index) {
            var total = 0;
			var day =<?=$maxDay?>+4;
			if(index>3&&index<day){
            $('.tr').each(function() {
                var value = parseInt($('td', this).eq(index).text());
                if (!isNaN(value)) {
                    total += value;
                }
            });
            $('table tfoot td').eq(index).text( total);
			}
		//if(total>avg1+1){ //평균에서 반올림한 숫자에 +1보다 클 경우 계속 새로 고침댐
		//				location.reload();
		//		}
        }


$(document).ready(function() {
		$('#choice').click(function() {
			var select = $("#select").val();
			alert(select);

			$.ajax({
				url : "<?php echo base_url(); ?>posting_plan",

				type : 'post',
			cache: false,
				data : { "select" : select },

				success : function(data) {
				alert("성공");
				$(".show_posting").show();
				}
			})
		});
	});

</script>

//여기가 뷰 코드입니다.. 아직 고치는중이라서 조금 지저분 합니다.... 감사합니다

 

한대승(불의회상) / 2021/09/30 17:16:08 / 추천 0

최종적으로 생성되는 html 코드에 답이 있을것 같습니다.

<form>...</form> 사이의 html을 잘 확인해 보세요.

테러보이 / 2021/10/01 09:00:41 / 추천 0

posting_data 를 컨트롤러에서 뿌려서 안나오는거면

post 전송으로 값이 안들어와서 일거고

 

뷰페이지에서 안나오는 거면 컨트롤러 view()의 $data에 posting_data를 포함 하지않아서 입니다.

경이 / 2021/10/01 10:01:04 / 추천 0
//한대승님 //테러보이님 감사합니다~~ 확인해보고 찾아서 고쳐보겠습니닷!