I am creating an XML generator that is working right, but I have reached the point where I have to insert the photos in xml and I do not know how to do it.
The "photos" tag should look like this:
<Fotos>
<Foto>
<URLArquivo>foto.jpg</URLArquivo>
</Foto>
<Foto>
<URLArquivo>foto2.jpg</URLArquivo>
</Foto>
</Fotos>
The photos are in another table of mysql, I have to make an inquiry inside another, that?
Below is my file (I just let the ID tag not leave a big code here):
$query = "
SELECT p.*, c.category_name, s.state_name, ct.city
FROM alk_osrs_properties p
LEFT JOIN (SELECT category_id, pid FROM alk_osrs_property_categories) pc ON pc.pid = p.id
LEFT JOIN (SELECT category_name, id FROM alk_osrs_categories) c ON c.id = pc.category_id
LEFT JOIN (SELECT state_name, id FROM alk_osrs_states) s ON s.id = p.state
LEFT JOIN (SELECT city, id FROM alk_osrs_cities) ct ON ct.id = p.city
";
$imoveisArray = array();
if ($result = $mysqli->query($query)) {
while ($row = $result->fetch_assoc()) {
array_push($imoveisArray, $row);
}
if(count($imoveisArray)){
createXMLfile($imoveisArray);
}
$result->free();
}
$mysqli->close();
function createXMLfile($imoveisArray){
$filePath = 'arquivo.xml';
$dom = new DOMDocument('1.0', 'utf-8');
$root = $dom->createElement('Imoveis');
for($i=0; $i<count($imoveisArray); $i++){
//INICIO DAS VARIAVEIS
$imovelId = $imoveisArray[$i]['id'];
$imovel = $dom->createElement('Imovel');
$id = $dom->createElement('CodigoImovel', $imovelId);
$imovel->appendChild($id);
$root->appendChild($imovel);
}
$dom->appendChild($root);
$dom->save($filePath);
}
The photos are in the table alk_osrs_photos, in the structure below, where pro_id is the main id of the property: id | pro_id | image
1 | 10 |foto.jpg
2 | 10 |foto2.jpg