json_encode() 배열 값 출력 질문 채택완료
ajax.php
</p>
<p> $address = array( '전체','서울','경기','인천','대전','대구','부산','광주','울산','세종','강원','충북','충남','전북','전남','경북','경남','제주' );</p>
<p> $address_2 = array( '','서울시','경기도','인천시','대전시','대구시','부산시','광주시','울산시','세종시','강원도','충청북도','충청남도','전라북도','전라남도','경상북도','경상남도','제주도' );</p>
<p> $address_3 = array( '','서울특별시','','인천광역시','대전광역시','대구광역시','부산광역시','광주광역시','울산광역시','세종특별자치시','강원특별자치도','','','','','','','제주특별자치도');//도시찾기 버튼으로 검색시</p>
<p> if($find_sido && $find_sigugun){ //select로 검색시</p>
<p> $sql = "select *</p>
<p> from sw_machine_holder</p>
<p> where machine_address like '$find_sido%' '$find_sigugun%'</p>
<p> or machine_address2 like '$find_sido%' '$find_sigugun%'</p>
<p> and mapLatitude > '' and</p>
<p> mapLongitude > '' and</p>
<p> petroom = 'Y'</p>
<p> GROUP BY petroom_name</p>
<p> ";</p>
<p> $row = "SELECT count(count) as total</p>
<p> FROM (SELECT count(petroom_name) as count FROM sw_machine_holder</p>
<p> WHERE petroom = 'Y' and machine_address like '$find_sido%' '$find_sigugun%' or machine_address2 like '$find_sido%' '$find_sigugun%' GROUP BY petroom_name)</p>
<p> as count";</p>
<p> </p>
<p> }else if( $find_machine ){ //text로 지점명 입력 검색시</p>
<p> // 우선 시 / 도 에있는 값인지 확인</p>
<p> if(in_array($find_machine ,$address)){</p>
<p> $sql = "select *</p>
<p> from sw_machine_holder</p>
<p> where machine_address like '$find_machine%'</p>
<p> and mapLatitude > '' and</p>
<p> mapLongitude > '' and</p>
<p> petroom = 'Y'</p>
<p> GROUP BY petroom_name</p>
<p> ";</p>
<p> } else {</p>
<p> $sql = "select *</p>
<p> from sw_machine_holder</p>
<p> where (machine_address REGEXP '$find_machine' or machine_address2 REGEXP '$find_machine') and petroom = 'Y'</p>
<p> GROUP BY petroom_name</p>
<p> ";</p>
<p> }</p>
<p> $row = "SELECT count(count) as total</p>
<p> FROM (SELECT count(petroom_name) as count FROM sw_machine_holder</p>
<p> WHERE petroom_name like '%$find_machine%'</p>
<p> or machine_address like '$find_machine%'</p>
<p> and mapLatitude > '' and</p>
<p> mapLongitude > '' and</p>
<p> petroom = 'Y'</p>
<p> GROUP BY petroom_name)</p>
<p> as count";</p>
<p> } else if( $find_address ) { //도시찾기 버튼으로 검색시</p>
<p> if($find_address == "전체"){</p>
<p> $sql = "select *</p>
<p> from sw_machine_holder</p>
<p> where mapLatitude > '' and</p>
<p> mapLongitude > '' and</p>
<p> petroom = 'Y'</p>
<p> GROUP BY petroom_name</p>
<p> ";</p>
<p> $row = "SELECT count(count) as total</p>
<p> FROM (SELECT count(petroom_name) as count FROM sw_machine_holder</p>
<p> WHERE petroom = 'Y'</p>
<p> and mapLatitude > '' and</p>
<p> mapLongitude > '' GROUP BY petroom_name)</p>
<p> as count";</p>
<p> }else {</p>
<p> $j = array_search( $find_address, $address ) === false ? ( array_search( $find_address, $address_2 ) === false ? array_search( $find_address, $address_3 ) : array_search( $find_address, $address_2 ) ) : array_search( $find_address, $address );</p>
<p> </p>
<p> if ( $j !== false ) {</p>
<p> $fine_address_like = " and ( ";</p>
<p> </p>
<p> if ( $address[$j] > '' ) {</p>
<p> $fine_address_like .= "machine_address like '" . $address[$j] . "%'";</p>
<p> " or machine_address like '" . $address_2[$j] . "%' or machine_address like '" . $address_3[$j] . "%' )";</p>
<p> }</p>
<p> if ( $address_2[$j] > '' ) {</p>
<p> if ( $fine_address_like != "( " ) {</p>
<p> $fine_address_like .= " or ";</p>
<p> }</p>
<p> $fine_address_like .= "machine_address like '" . $address_2[$j] . "%'";</p>
<p> }</p>
<p> if ( $address_3[$j] > '' ) {</p>
<p> if ( $fine_address_like != "( " ) {</p>
<p> $fine_address_like .= " or ";</p>
<p> }</p>
<p> $fine_address_like .= "machine_address like '" . $address_3[$j] . "%'";</p>
<p> }</p>
<p> if ( $fine_address_like != "( " ) {</p>
<p> $fine_address_like .= " ) ";</p>
<p> }</p>
<p> }</p>
<p> </p>
<p> $sql = "select *</p>
<p> from sw_machine_holder</p>
<p> where</p>
<p> mapLatitude > '' and</p>
<p> mapLongitude > '' and</p>
<p> petroom = 'Y'</p>
<p> $fine_address_like</p>
<p> GROUP BY petroom_name</p>
<p> ";</p>
<p> $row = "SELECT count(count) as total</p>
<p> FROM (SELECT count(petroom_name) as count FROM sw_machine_holder</p>
<p> WHERE petroom = 'Y' and machine_address like '$find_address%' GROUP BY petroom_name)</p>
<p> as count"; </p>
<p> $status = "select * from sw_machine_holder where petroom = 'Y' and admin_status = '이용가능'"; </p>
<p> }</p>
<p> } else { //위 세가지가 안먹을 시</p>
<p> $sql = "select *</p>
<p> from sw_machine_holder</p>
<p> where mapLatitude > '' and</p>
<p> mapLongitude > '' and</p>
<p> petroom = 'Y' and</p>
<p> petroom_name != ''</p>
<p> GROUP BY petroom_name ";</p>
<p> </p>
<p> $row = "SELECT count(count) as total</p>
<p> FROM (SELECT count(petroom_name) as count FROM sw_machine_holder</p>
<p> WHERE petroom = 'Y'</p>
<p> and mapLatitude > '' and</p>
<p> mapLongitude > '' GROUP BY petroom_name)</p>
<p> as count";</p>
<p> }</p>
<p> $query = sql_query( $sql );</p>
<p> $machine_count = sql_query($row);</p>
<p> $mapNameArray = array();</p>
<p> $statusArray = array();</p>
<p> $latArray = array();</p>
<p> $lotArray = array();</p>
<p> $arr = array();</p>
<p> $arr["data"] = array();</p>
<p> </p>
<p> for($i=0; $row=sql_fetch_array($query); $i++){</p>
<p> </p>
<p> $find_status_sql = sql_fetch("select * from sw_machine_data where petroom = 'Y' and data2 = '{$row['machine_uuid']}' order by idx desc limit 1");</p>
<p> $find_status = $find_status_sql['data1'];</p>
<p> $make_status = explode(' ', $find_status);</p>
<p> </p>
<p> $mapNameArray[$i] = $row['petroom_name'];</p>
<p> $latArray[$i] = $row['mapLatitude'];</p>
<p> $lotArray[$i] = $row['mapLongitude'];</p>
<p> </p>
<p> $status_check = sql_fetch("select petroom_name from sw_machine_holder where petroom = 'Y' and admin_status != '사용불가능' and petroom_name ='$mapNameArray[$i]'");</p>
<p> </p>
<p> if($status_check['petroom_name'] == $mapNameArray[$i]){</p>
<p> $statusArray[$i] = "이용가능";</p>
<p> $row['admin_status'] = "이용가능";</p>
<p> } else {</p>
<p> $statusArray[$i] = "이용불가";</p>
<p> $row['admin_status'] = "이용불가";</p>
<p> }</p>
<p> }</p>
<p> array_push( $arr["data"], $mapNameArray);</p>
<p> array_push( $arr["data"], $latArray);</p>
<p> array_push( $arr["data"], $lotArray);</p>
<p> array_push( $arr["data"], $statusArray);</p>
<p> </p>
<p> //var_dump( $arr );</p>
<p>// echo json_decode( $arr );</p>
<p> //$data = json_decode( $arr );</p>
<p> echo json_encode( $arr );</p>
<p>?> </p>
<p>
form안에 있는 value값들을 ajax로 받아서 for문을 돌려 나온 값들을 json 배열에 담아 보냈습니다.
</p>
<p> $.ajax({</p>
<p> type: "POST",</p>
<p> url: ajax_url,</p>
<p> data: frmData,</p>
<p> dataType: "JSON",</p>
<p> success: function(response) {</p>
<p> </p>
<p> console.log(response);</p>
<p> },</p>
<p>
이렇게 console을 찍어보니

이렇게 찍히는데 문제는 나온 배열 값들을
</p>
<p> <h4></p>
<p><?php echo $mapNameArray[$i] ;?></p>
<p> </h4></p>
<p>
이렇게 출력할수는 없나요?? 위에 코드도 생략되었지만 ajax 페이지와 같이 for문을 돌렸을때 원하는 값을 찾기 위한 코드입니다.
아니면 ajax처리에서 배열로 보내면 안되는것이었나요..
아니면 console로 찍힌 저 배열들을