Building XML from MySQL via PHP

Hiya Guys,

I’m trying to create a simple XML string from a MySQL database via PHP.

Currently I have a MySQL database built, and am using this function, which is working well:

function createxml($x) {
global $mysqli;
$sxe = new SimpleXMLElement($xmlstr);
//get mysql data
if ($result = $mysqli->query(“SELECT id,county,main_page,lat,lon,volume,texty,pdf,thumb FROM texts3 ORDER BY id ASC LIMIT $x”))

//found volumes already in DB
while ($r = $result->fetch_array(MYSQLI_BOTH)) {
$record = $sxe->addChild(‘record’);
$record->addChild(‘title’, $r[‘county’]);
$record->addChild(‘creator’, ‘’);
$record->addChild(‘description’, $r[‘texty’]);
$record->addChild(‘latitude’, $r[‘lat’]);
$record->addChild(‘longitude’, $r[‘lon’]);
$record->addChild(‘latlon’, $r[]);
$record->addChild(‘identifier’, $r[‘id’]);
$record->addChild(‘isShownAt’, ‘’.$r['id’]);
$record->addChild(‘thumb’, ‘’.$r['thumb’]);
$record->addChild(‘publisher’, ‘’);
$record->addChild(‘date’, date(‘Y’));
$record->addChild(‘format’, ‘TEXT’);
$record->addChild(‘spatial’, ‘’);
$record->addChild(‘provider’, ');
$record->addChild(‘rights’, 'All rights reserved. ');
$record->addChild(‘subject’, ‘name books and letters,’);

What I am trying to do is very simple: for the ‘latlon’ variable, I would simply like $lat and $lon to be combined.

So it would be ouputed, in normal PHP, like: $latlon = $lat. “,”. $lon;

How would I combine these two elements in to be outputted in the XML?

Sponsor our Newsletter | Privacy Policy | Terms of Service