only the one recordset is needed.
Hers what you need to do:
Before the loop create a variable for the name, and set it to blank
<?php $nameStr = ""; ?>
inside the loop add an if statement to determine if the name tag should be written. and set the value of nameStr to the value ion the recordset.
the first time, you wont need to close the name tab, but subsequent times through, you will
if($nameStr != $row_Recordset1['name']) {
if($nameStr != "") fwrite($fp, '</item>');
fwrite($fp, '<item Name="'.$row_Recordset1['name'].'">');
$nameStr = $row_Recordset1['name'];
}
full code:
<?php
mysql_select_db($database_dbconnect, $dbconnect);
$query_Recordset1 = "SELECT * FROM mytable GROUP BY name";
$Recordset1 = mysql_query($query_Recordset1, $dbconnect) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<?php
$fp = fopen('example.xml', 'w+');
fwrite($fp, '<?xml version="1.0" encoding="utf-8" ?>');
fwrite($fp, '<content>');
?>
<?php $nameStr = ""; ?>
<?php do {
if($nameStr != $row_Recordset1['name']) {
if($nameStr != "") fwrite($fp, '</item>');
fwrite($fp, '<item Name="'.$row_Recordset1['name'].'">');
$nameStr = $row_Recordset1['name'];
}
fwrite($fp, '<image="'.$row_Recordset1['image'].'">');
fwrite($fp, '<text>');
fwrite($fp, '<![CDATA[Lorem ipsum dolor sit amet, consectetuer.]]>');
fwrite($fp, '</text>');
fwrite($fp, '</image>');
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
fwrite($fp, '</item>');
?>
<?php
fwrite($fp, '</content>');
fclose($fp);
?>