<?php
    include_once 'opendb.php';
    $xml          = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    $root_element = "Subs"; //fruits
    $xml         .= "<".$root_element.">";
    $filter="";
    $Option="";
     $Qry="SELECT mobile,sub_name,address,place,phone,sman_code,reg_no1,edit_time,area_name,inactive,email,app_pass,create_source, sub_code,country_code,street_name,bldg_no,city,district,id_type,name_ar,add1_ar,add2_ar,add3_ar FROM `subsidiary`  ";
     //last_edit_time
    $Qry.= " where  comp_id=".$_GET["comp_id"]." and create_source=2 and edit_time>=".$_GET["last_edit_time"] ;
    
   // echo $Qry;
    $result = $conn->query($Qry) or die(mysqli_error($conn));
   header("Content-Type: application/xml");
   echo sqlToXml($result, "Subs", "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; 
}


    
    
?>