i have table:
Date text
09/03/2003 a999999
09/03/2003 b999999
10/03/2003 a101010
11/03/2003 a111111
php code:
<?php
header("Content-type: text/xml");
$host = "localhost";
$user = "root";
$pass = "";
$database = "test";
$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $linkID) or die("Could not find database.");
$query = "SELECT * FROM blog ORDER BY date DESC";
$resultID = mysql_query($query, $linkID) or die("Data not found.");
$xml_output = "<?xml version=\"1.0\"?>
";
$xml_output .= "<entries>
";
for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
$row = mysql_fetch_assoc($resultID);
$xml_output .= " <entry>
";
$xml_output .= " <date>" . $row['date'] . "</date>
";
// Escaping illegal characters
$row['text'] = str_replace("&", "&", $row['text']);
$row['text'] = str_replace("<", "<", $row['text']);
$row['text'] = str_replace(">", ">", $row['text']);
$row['text'] = str_replace("\"", """, $row['text']);
$xml_output .= " <text>" . $row['text'] . "</text>
";
$xml_output .= " </entry>
";
}
$xml_output .= "</entries>";
echo $xml_output;
?>
output:
<entries>
<entry>
<date>11/03/2003</date>
<text>a111111</text>
</entry>
<entry>
<date>10/03/2003</date>
<text>a101010</text>
</entry>
<entry>
<date>09/03/2003</date>
<text>b999999</text>
</entry>
<entry>
<date>09/03/2003</date>
<text>a999999</text>
</entry>
</entries>
i want output like:
<date label='11/03/2003'>
<text label='a111111' />
</date>
<date label='10/03/2003'>
<text label='a101010' />
</date>
<date label='09/03/2003'>
<text label='a999999' />
<text label='b999999' />
</date>
output group by date
<date label='09/03/2003'>
<text label='a999999' />
<text label='b999999' />
</date>
how php code for case above?