<?php
ob_start();
session_start();
require_once("../conn/conn.php");
//include('../utility/chksession.php');

$id_po= $_REQUEST['id_po'];

echo $id_po;?></br><?


    $strSQL = "SELECT * FROM pd_po where id_po='$id_po'";
    $objQuery = mysqli_query($con,$strSQL);  
    $objResult = mysqli_fetch_array($objQuery);
    $no_po=$objResult['no_po'];
  
    echo  $no_po;?></br><?
    
    $strSQL1 = "SELECT * FROM `pd_posub` where id_po='$id_po';";
    $objQuery1 = mysqli_query($con,$strSQL1);  
    
    while($objResult1 = mysqli_fetch_array($objQuery1)){
    $id_posub=$objResult1['id_posub'];
   
     echo $id_posub;?></br><?
	 
	 
	 
		$strSQL2 = "SELECT * FROM `pd_jobver` where id_posub='$objResult1[id_posub]';";
		$objQuery2 = mysqli_query($con,$strSQL2);  
		
	 	while($objResult2 = mysqli_fetch_array($objQuery2)){
			
			echo $objResult2['ver_id'];?></br><?
			
			$sql2 = "DELETE FROM pd_jobver WHERE id_posub='$objResult1[id_posub]'";
        	$query2 = mysqli_query($con,$sql2);
			
			
		}
		
		$strSQL3 = "SELECT * FROM `pd_ver` where id_posub='$objResult1[id_posub]';";
		$objQuery3 = mysqli_query($con,$strSQL3);  
		
	 	while($objResult3 = mysqli_fetch_array($objQuery3)){
			
			echo $objResult3['ver_id'];?></br><?
			
			$sql3 = "DELETE FROM pd_ver WHERE id_posub='$objResult1[id_posub]'";
        	$query3 = mysqli_query($con,$sql3);
			
		}
		
		$strSQL4 = "SELECT * FROM `pd_job` where id_posub='$objResult1[id_posub]';";
		$objQuery4 = mysqli_query($con,$strSQL4);  
		
	 	while($objResult4 = mysqli_fetch_array($objQuery4)){
			
			echo $objResult4['job_pdid'];?></br><?
			
			$sql4 = "DELETE FROM pd_jobsub WHERE id_posub='$objResult1[id_posub]'";
        	$query4 = mysqli_query($con,$sql4);
			
		}
		
		$strSQL5 = "SELECT * FROM `pd_jobsub` where id_posub='$objResult1[id_posub]';";
		$objQuery5 = mysqli_query($con,$strSQL5);  
		
	 	while($objResult5 = mysqli_fetch_array($objQuery5)){
			
			echo $objResult5['job_pdid'];?></br><?
			
			
			$sql5 = "DELETE FROM pd_jobsub WHERE id_posub='$objResult1[id_posub]'";
        	$query5 = mysqli_query($con,$sql5);
			
			
		}
		$strSQL6 = "SELECT * FROM `pd_history` where id_posub='$objResult1[id_posub]';";
		$objQuery6 = mysqli_query($con,$strSQL6);  
		
	 	while($objResult6 = mysqli_fetch_array($objQuery6)){
			
			echo $objResult6['pdh_id'];?></br><?
			
			$sql6 = "DELETE FROM pd_history WHERE id_posub='$objResult1[id_posub]'";
        	$query6 = mysqli_query($con,$sql6);
			
		}
		
		$strSQL7 = "SELECT * FROM `pd_job` where id_posub='$objResult1[id_posub]';";
		$objQuery7 = mysqli_query($con,$strSQL7);  
		
	 	while($objResult7 = mysqli_fetch_array($objQuery7)){
			
			echo $objResult7['jobh_id'];?></br><?
			
			$sql7 = "DELETE FROM pd_job WHERE id_posub='$objResult1[id_posub]'";
        	$query7 = mysqli_query($con,$sql7);
			
		}
		
	
		
     
     
    }
    


    $sql = "DELETE FROM pd_po where id_po='$id_po'";
	$query = mysqli_query($con,$sql);

	
    $sql_sub = "DELETE FROM `pd_posub` where id_po='$id_po';";
	$querysub = mysqli_query($con,$sql_sub);
	
	
	
        if($query){
            ?>
                <script language="JavaScript" type="text/javascript">
                    <!--
                    alert("ลบข้อมูลเรียบร้อย!!");
                    location.href='../admin/data_po.php';
                    //-->
                </script>
            <?php
        }else{
            
            echo "Error: " . $sql . "<br>" . mysqli_error($con);

        }
        mysqli_close($con);

?>