<?php
    include_once 'opendb.php';
    $xml          = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
    $root_element = "Products"; //fruits
    $xml         .= "<".$root_element.">";
    $CompID=$_GET["comp_id"]; 
    $last_edit_time=$_GET["last_edit_time"]; 
    $Qry="SELECT * from products where edit_time >$last_edit_time and comp_id=$CompID order by edit_time";
   // die($Qry);
   $result = $conn->query($Qry) or die(mysqli_error($conn). $Qry); 
   header("Content-Type: application/xml");
   echo sqlToXml($result, "Products", "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; 
}


    
    
?>