foreach ($result as $row)
$file_handle = fopen('R.xml','a');
In other words for every row in the result, you reopen the XML file for appending (and that's all you do before going on to the next row, funnily enough).
Of course having anything else in the file before or after
<?xml version="1.0" ?>
<results>
<result>42</result>
</results>
would render it invalid as an XML file - it would no longer be well-formed.
You don't mean something more like
<?php
$file_handle = fopen('R.xml','a');
$content = '<?xml version="1.0"?>
<results>';
foreach ($result as $row)
{
$content.="\n<result>".$row->mark."</result>\n";
}
$content .="</results>";
fwrite($file_handle,$content);
fclose($file_handle);
?>
Perhaps?
This isn't really a PHP5 problem, as PHP4 would behave the same way (so I guess this isn't a PHP4-PHP5 migration problem of the sort this forum was created for).