agregar múltiples datos en un archivo xml usando PHP xmlwriter
Necesito agregar un artículo para cada mes enxml
archivo usando PHPxmlwriter
:
$sql = "SELECT *,YEAR(FROM_UNIXTIME(timestamp)) AS YEAR,
MONTH(FROM_UNIXTIME(timestamp)) AS MONTH
FROM ".NEWS_ARTICLES." GROUP BY YEAR, MONTH ORDER BY YEAR DESC, MONTH ";
$newsdata = DataAccess::Fetch($sql);
foreach($newsdata AS $news){
$writer->openURI('./cache/xmls/posts-'.$news['MONTH'].'-'.$news['YEAR'].'.xml');
$writer->startDocument('1.0','UTF-8');
$writer->setIndent(4);
$writer->startElement('urlset');
$writer->writeAttribute('xmlns', $xmlns);
$writer->startElement('url');
$writer->writeElement('loc',$news['title']);
$writer->endElement();
$writer->endElement();
$writer->endDocument();
$writer->flush();
}
Esto funcionó para mí y generar.xml
archivo para cada mes Pero no agrego el título de todos los artículos para cada mes y solo veoone
título en el archivo de cada mes !! ¿Cómo puedo agregar todos los artículos de cada mes en archivos xml?
Creo que mi problema es con el bucle !!!
resultado:posts-5-2015.xml
<url>
<loc>title</loc>
</url>
En Really tengo 5 artículos y necesito:
resultado:posts-5-2015.xml
<url>
<loc>title</loc>
</url>
<url>
<loc>title2</loc>
</url>
<url>
<loc>title3</loc>
</url>
<url>
<loc>title4</loc>
</url>
<url>
<loc>title5</loc>
</url>
print_r($newsdata)
resultado: NOTA: esto es simple de DB grande y solo para esquema
Array
(
[0] => Array
(
[id] => 243
[title] => test2
[story] => desc2
[timestamp] => 1442389680
[update_time] => 1442389522
[YEAR] => 2015
[MONTH] => 9
)
[1] => Array
(
[id] => 242
[title] => test1
[story] => desc
[timestamp] => 1421230680
[update_time] => 1441026399
[YEAR] => 2015
[MONTH] => 1
)
[2] => Array
(
[id] => 244
[title] => test3
[story] => desc3
[timestamp] => 1421230680
[update_time] => 1441026399
[YEAR] => 2015
[MONTH] => 5
)
[3] => Array
(
[id] => 245
[title] => test4
[story] => desc4
[timestamp] => 1421230680
[update_time] => 1441026399
[YEAR] => 2015
[MONTH] => 5
)
[4] => Array
(
[id] => 246
[title] => test5
[story] => desc5
[timestamp] => 1421230680
[update_time] => 1441026399
[YEAR] => 2015
[MONTH] => 5
)
[5] => Array
(
[id] => 247
[title] => test6
[story] => desc6
[timestamp] => 1421230680
[update_time] => 1441026399
[YEAR] => 2015
[MONTH] => 5
)
[6] => Array
(
[id] => 248
[title] => test7
[story] => desc7
[timestamp] => 1421230680
[update_time] => 1441026399
[YEAR] => 2015
[MONTH] => 5
)
)