<?php
$departmentid = $_REQUEST['department'];
$doctorid = $_REQUEST['doctor'];
// URL to the web service
$url = 'http://117.240.62.146/iiislifelineobapi/srvBkAPI.asmx/getDoctor?dept_id=' . $departmentid . '&dname=';
// Fetch the XML content from the URL
$xmlResponse = file_get_contents($url);
if ($xmlResponse === false) {
    // Handle the error if the URL couldn't be fetched
    echo "Failed to fetch data from the URL.";
} else {
    // Use SimpleXML to parse the XML response
    $xml = simplexml_load_string($xmlResponse);
    if ($xml === false) {
        // Handle XML parsing error
        echo "Failed to parse XML response.";
    } else {
        // Extract the JSON content from the XML element
        $jsonString = (string)$xml;
        // Decode the JSON string into a PHP array
        $data = json_decode($jsonString, true);
        if ($data === null) {
            // Handle JSON decoding error
            echo "Failed to decode JSON data.";
        } else {
            // Now you can access and use the JSON data as needed
            // For example, to access the first item in the array:
            foreach ($data as $item) {
                $id = $item['Id'];
                $name = $item['Name'];
                // Use the extracted data as needed
?>
                <option value="<?php echo $id; ?>" <?php if ($id == $doctorid) {
                                                        echo "selected";
                                                    } ?>><?php echo $name; ?></option>
<?php
            }
            // Use the extracted data as needed
            // echo "ID: $id, Name: $name";
        }
    }
}
?>