Salve ragazzi io ho sue tabelle sul database, che sono le seguenti:
codice:
tabella "categoria"
id_categoria(PK) - nome
1 Gossip
2 Veline
tabella "immagine"
id_immagine(PK) - id_categoria(FK) data - titolo - descrizione - path
1- 1- 07/03/2011-Titolo 1 Descrizione 1-Path1
2- 1- 07/03/2011-Titolo 2 Descrizione 2-Path2
3- 1- 07/03/2011-Titolo 3 Descrizione 3-Path3
4- 2- 07/03/2011-Titolo 4 Descrizione 4-Path4
5- 2- 07/03/2011-Titolo 5 Descrizione 5-Path5
Adesso dovrei generare un file xml chiamato "gallery.xml", in base ai valori delle tabelle...
l'output del file xml dovrebbe essere una cosa di questo tipo:
codice:
<gallery title="Nome" thumbDir="./images/thumbs/" imageDir="./images/" random="true">
<category name="Gossip">
<image>
<date>Lavori</date>
<title>Titolo 1</title>
<desc>Lavori</desc>
<thumb>modulaartwork (4).jpg</thumb>
<img>modulaartwork (4).jpg</img>
</image>
<image>
<date>Lavori</date>
<title>Titolo 2</title>
<desc></desc>
<thumb>modulaartwork (2).jpg</thumb>
<img>modulaartwork (2).jpg</img>
</image>
<image>
<date>Lavori</date>
<title>Titolo 3/title>
<desc></desc>
<thumb>modulaartwork (3).jpg</thumb>
<img>modulaartwork (3).jpg</img>
</image>
</category>
<category name="Calciatori">
<image>
<date>Lavori</date>
<title>Titolo 4</title>
<desc>Lavori</desc>
<thumb>modulaartwork (4).jpg</thumb>
<img>modulaartwork (4).jpg</img>
</image>
<image>
<date>Lavori</date>
<title>Titolo 5</title>
<desc></desc>
<thumb>modulaartwork (2).jpg</thumb>
<img>modulaartwork (2).jpg</img>
</image>
<image>
<date>Lavori</date>
<title>Modula Gioielli</title>
<desc></desc>
<thumb>modulaartwork (3).jpg</thumb>
<img>modulaartwork (3).jpg</img>
</image>
</category>
</gallery>
Io avevo fatto una cosa di questo tipo in php (xmlCreate.php)
Codice PHP:
<?php
include ("connessione.php");
$sql = "select * from categoria";
$result = mysql_query($sql) or die ("Errore nella selezione delle squadre " . mysql_error());
$elements
//Creates XML string and XML document using the DOM.
$xml = new DomDocument('1.0');
// Create some elements.
$xml_gallery = $xml->createElement( "gallery" );
$xml_image = $xml->createElement( "images" );
$xml_date = $xml->createElement( "date" );
$xml_title = $xml->createElement( "title" );
$xml_desc = $xml->createElement( "desc" );
$xml_thumb = $xml->createElement( "thumb" );
$xml_img = $xml->createElement( "img" );
// Set the attributes for tag <gallery>
$xml_gallery->setAttribute( "title", "Modula Gioielli" );
$xml_gallery->setAttribute( "thumbDir", "./images/thumbs/" );
$xml_gallery->setAttribute( "imageDir", "./images/" );
$xml_gallery->setAttribute( "random", "true" );
while ($row = mysql_fetch_array($result)) {
// Create element <category>.
$xml_category = $xml->createElement( "category" );
// Set the attributes for tag <category>
$xml_category->setAttribute( "name", $row['nome'] );
// Altro ciclo per le immagini associate alla categoria
// Append the whole bunch.
$xml_gallery->appendChild( $xml_category );
$xml_category->appendChild( $xml_image );
$xml_image->appendChild( $xml_date );
$xml_image->appendChild( $xml_title );
$xml_image->appendChild( $xml_desc );
$xml_image->appendChild( $xml_thumb );
$xml_image->appendChild( $xml_img );
// Chiudi ciclo 2
} // Chiudi ciclo 1
$test = $xml->saveXML(); // put string in test1
$xml->save('gallery.xml'); // save as file
Non sò se vada bene una cosa del genere, eventualmente qualcuno potrebbe farmi capire come completare il file xmlCreate.php.
P.S
Ovviamente penso che si dovrà creare una join per estrapolare i dati? è così? io ho provata a farla ma non funge come dovrebbe
Grazie anticipatamente,
Gaten