<?php
//-----------------------------------------------------------------------------------
//Turning a 2 dimentional PHP array into a standard XML output
//    Array has first dimension as indexed array, 2nd dimension is keyed array
//The XML string could be sent to JavaScript for processing
//-----------------------------------------------------------------------------------

$data = array( array("student_id"=>123, "fname"=>"Barbara", "lname"=>"Burns",  "sex"=>"F"),
               array("student_id"=>124, "fname"=>"David",   "lname"=>"Runyon", "sex"=>"M"),
               array("student_id"=>125, "fname"=>"Patrick", "lname"=>"Stack",  "sex"=>"M"),
             );

//header("Content-type: text/xml");                               // inform the browser that 
                                                                  // you are sending XML
$xmlString .= "<?xml version='1.0' ?> \n";

$xmlString .= "<sqlData> \n";

foreach( $data as $row )                                          // loop thru the rows
{
    $xmlString .= "  <row> \n";

    foreach( $row as $colName => $colValue)                       // loop thru column names/values
        $xmlString .=  "    <$colName> $colValue </$colName> \n";

    $xmlString .= "  </row> \n";
}


$xmlString .= "</sqlData> \n";

print "<textarea style='width:500%; height:500%'>";             //so XML displays properly              
print "$xmlString";
print "</textarea>";
        
?>