简体   繁体   中英

Difficulty in exporting XML from MySQL database via PHP using SimpleXML

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);

        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM