<?php
    include_once 'opendb.php';
    $filter="";
    $xml          = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    $root_element = "SaleOrders"; //fruits
    $xml         .= "<".$root_element.">";
    $WebEntryNo=$_GET["WebEntry_No"];
    if (!isset($WebEntryNo)){
       die("WebEntryno required");
    }
    $SubTable="delivery_sub ";
   
    
    $Qry="SELECT  order_no,sub_code,Route_SLNO,Is_Delivered FROM ".$SubTable." where WEntry_no=".$WebEntryNo;
    $result = $conn->query($Qry) or die(mysqli_error($conn). $Qry); 
    
   header("Content-Type: application/xml");
   echo sqlToXml($result, "Delivery", "Rows");
   $conn->close(); 
  
function sqlToXml($queryResult, $rootElementName, $childElementName)
{ 
    $xmlData = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n"; 
    $xmlData .= "<" . $rootElementName . ">";
    
    while ($row = mysqli_fetch_assoc($queryResult))
    {
            $xmlData .= "<" . $childElementName . ">";
            foreach( $row as $field => $value) {
             
            // echo "<"."{$field}".">"."  - {$value}<br>";

                $xmlData .= "<{$field}>{$value}</{$field}>";
            }
            $xmlData .= "</" . $childElementName . ">"; 
    }
 
   
    $xmlData .= "</" . $rootElementName . ">"; 
 
    return $xmlData; 
}


    
    
?>