使用SimpleXML通过PHP从MySQL数据库导出XML很困难

I'm a complete novice, and have been asked to finish a project for someone (much more knowledgeable than I) who has just left.

I currently have a MySQL database, which I am trying to export as an XML file. This is going fine, but unlike PHP, I can't combine two separate columns.

So where I have two entries - lat (latitude), and Lon (longitude) - in my MySQL database, I can't output them in XML as one entry.

In PHP I would simply write: $latlon = $lat.",".$lon;

But I cannot do so in the XML output below.

Does anyone know how I could write this to achieve the required result, of simply having two entries listed under one child?

function createxml($x) {
    global $mysqli;
    include('xml.php');
    $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('latitude', $r['lat']);
            $record->addChild('longitude', $r['lon']);
            $record->addChild('latlon', $r['']);



        }
    $result->close();
}

If you have the r array why don't you try:

while ($r = $result->fetch_array(MYSQLI_BOTH)) {
            $record = $sxe->addChild('record');
             $latlon = $r['lat'].",".$r['lon'];

            $record->addChild('latitude', $r['lat']);
            $record->addChild('longitude', $r['lon']);
            $record->addChild('latlon', $latlon);

        }