$conn = mysqli_connect(
  'localhost',
  'jaewon_ivis',
  'jw123!@#',
  'ivis');
  
	date_default_timezone_set("Asia/Seoul");
	$today = date('Y-m-d H:i:s');
	$title_key = $_REQUEST['serial'];
	
	if($title_key!=null && strlen($title_key) > 5 ){	
		$results = mysqli_query($conn, "SELECT * FROM `wp_kboard_board_content` WHERE title='$title_key'");
			
		if(!$results){ die('Error : '.mysqli_error($conn)); }
		
		if(mysqli_num_rows($results) > 0 ){
			
			$row1 = mysqli_fetch_object($results);
			$query01 = mysqli_query($conn, "SELECT * FROM `wp_kboard_board_option` WHERE content_uid='$row1->uid' and option_key='custom_name'");
			$query02 = mysqli_query($conn, "SELECT * FROM `wp_kboard_board_option` WHERE content_uid='$row1->uid' and option_key='custom_car'");
			$query03 = mysqli_query($conn, "SELECT * FROM `wp_kboard_board_option` WHERE content_uid='$row1->uid' and option_key='custom_car_num'");
			$query04 = mysqli_query($conn, "SELECT * FROM `wp_kboard_board_option` WHERE content_uid='$row1->uid' and option_key='custom_pn'");
			$query05 = mysqli_query($conn, "SELECT * FROM `wp_kboard_board_option` WHERE content_uid='$row1->uid' and option_key='custom_price_date'");
			
			if(mysqli_num_rows($query01) > 0) $custom_name 		= mysqli_fetch_object($query01)->option_value; else $custom_name = " ";
			if(mysqli_num_rows($query02) > 0) $custom_car 		= mysqli_fetch_object($query02)->option_value; else $custom_car = " ";
			if(mysqli_num_rows($query03) > 0) $custom_car_num 	= mysqli_fetch_object($query03)->option_value; else $custom_car_num = " ";
			if(mysqli_num_rows($query04) > 0) $custom_pn 		= mysqli_fetch_object($query04)->option_value; else $custom_pn = " ";
			if(mysqli_num_rows($query05) > 0) $custom_price_date = mysqli_fetch_object($query05)->option_value; else $custom_price_date = " ";
				
			if($row1->category1!=null && strlen($row1->category1) > 5){ $tmp = explode(' ',$row1->category1);  $cat1 = $tmp[7].$tmp[8]; } else $cat1 = " ";
			if($row1->category2!=null && strlen($row1->category2) > 5){ $tmp = explode(' ',$row1->category2);  $cat2 = $tmp[7].$tmp[8]; } else $cat2 = " ";
			if($row1->category3!=null && strlen($row1->category3) > 5){ $tmp = explode(' ',$row1->category3);  $cat3 = $tmp[7].$tmp[8]; } else $cat3 = " ";
			if($row1->category4!=null && strlen($row1->category4) > 5){ $tmp = explode(' ',$row1->category4);  $cat4 = $tmp[7].$tmp[8]; } else $cat4 = " ";
			if($row1->category5!=null && strlen($row1->category5) > 5){ $tmp = explode(' ',$row1->category5);  $cat5 = $tmp[7].$tmp[8]; } else $cat5 = " ";
			if($row1->category6!=null && strlen($row1->category6) > 5){ $tmp = explode(' ',$row1->category6);  $cat6 = $tmp[7].$tmp[8]; } else $cat6 = " ";
			if($row1->category7!=null && strlen($row1->category7) > 5){ $tmp = explode(' ',$row1->category7);  $cat7 = $tmp[7].$tmp[8]; } else $cat7 = " ";
			
			$date = date("Y-m-d", strtotime( $row1->date ) );
			
			$EXCEL_STR=" 
			<table border='1'>
			<tr><td>등록일자</td><td>".$date."</td></tr>
			<tr><td>보증번호</td><td>".$row1->title."</td></tr>
			<tr><td>시공일자</td><td>".$custom_price_date."</td></tr>
			<tr><td>차종</td><td>".$custom_car."</td></tr>
			<tr><td>차량번호</td><td>".$custom_car_num."</td></tr>
			<tr><td>대리점</td><td>".$row1->member_display."</td></tr>
			<tr><td>고객명</td><td>".$custom_name."</td></tr>
			<tr><td>고객전화번호</td><td>".$custom_pn."</td></tr>
			<tr><td>전면</td><td>".$cat1."</td></tr>
			<tr><td>측면1열</td><td>".$cat2."</td></tr>
			<tr><td>측면2열</td><td>".$cat3."</td></tr>
			<tr><td>측면3열</td><td>".$cat4."</td></tr>
			<tr><td>후면</td><td>".$cat5."</td></tr>
			<tr><td>파노라마</td><td>".$cat6."</td></tr>
			<tr><td>썬루프</td><td>".$cat7."</td></tr></table>";
			
		}	
			
	echo "<meta http-equiv='Content-Type' content='text/html; charset=utf-8'> ".$EXCEL_STR;
			
	}	
