Autor Zpráva
prem
Profil *
Zdravím,

mám flashovou galerii, která je "naplněna" pomocí xml souboru. Můj problém je samozřejmě ten, jestli jde nějak načíst data z mysql databáze a uložit je do xml souboru na serveru.

Napadlo mě něco takového:

$text = "data z databáze jako obsah xml";
$soubor = fopen("gallery.xml", "a+");
fwrite($soubor, $text);
fclose($soubor);


problém je jestli půjde vytvořit takto xml soubor a jak načíst do proměnné data pro xml...
Medvídek
Profil
http://interval.cz/clanky/tvorba-xml-vystupu-v-php/

V OC sepoužívalo toto :

Header( 'Content-Type: text/xml' ); 

echo '<?xml version="1.0" ?>';
echo '<' . $xml_tags['master'] . '>';
if ($show_creation_time == 1) {
$timestamp = date("D M j G:i:s T Y");
echo '<' . $xml_tags['time'] . ' value="' . $timestamp . '">';
}
$connection = mysql_connect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD) or die("OSC XML FEED FAILURE - Couldn't make connection to local database.");
$db = mysql_select_db(DB_DATABASE, $connection) or exit("OSC XML FEED FAILURE - Error code: " . mysql_errno($connection) . " Error: " . mysql_error($connection) . ".");
$product_query = "SELECT `products`.`products_id`,`products`.`products_quantity`,`products`.`pr oducts_model`,`products`.`products_image`,`products`.`products_price`, `products`.`products_date_added`,`products`.`products_last_modified`,` products`.`products_date_available`,`products`.`products_weight`,`prod ucts`.`products_status`,`products`.`manufacturers_id`,`products_descri ption`.`products_name`,`products_description`.`products_url`, `manufacturers`.`manufacturers_name` FROM `products` INNER JOIN `products_description` ON (`products`.`products_id` = `products_description`.`products_id`) INNER JOIN `manufacturers` ON (`products`.`manufacturers_id` = `manufacturers`.`manufacturers_id`)";
if(($allow_all == "0") && ($allow_no_stock == "0")) {
$product_query .= " WHERE (`products`.`products_status` = 1) AND (`products`.`products_quantity` > 0)";
}
else {
if($allow_all == "0") { $product_query .= " WHERE (`products`.`products_status` = 1)"; }
if($allow_no_stock == "0") { $product_query .= " WHERE (`products`.`products_quantity` > 0)"; }
}
$product_query_result = mysql_query($product_query,$connection) or exit("<hr>code: " . mysql_errno($connection) . " error: " . mysql_error($connection) . ".");
$product_query_count = mysql_numrows($product_query_result);
if ($product_query_count > 0) {
while ($row = mysql_fetch_array($product_query_result)) {
//------------------------------------------------------------------- ---------------------------
// START -> insert any custom sql queries for extra tags here
//------------------------------------------------------------------- ---------------------------

//------------------------------------------------------------------- ---------------------------
// END -> insert any custom sql queries for extra tags here
//------------------------------------------------------------------- ---------------------------

$row['products_price'] = tep_round($row['products_price'], 2);
if ($pricing_show_specials == 1) {
$specials_query = "SELECT `specials`.`specials_new_products_price` FROM `specials` WHERE (`specials`.`products_id` = " . $row['products_id'] . ")";
$specials_result = mysql_query($specials_query,$connection) or exit("<hr>code: " . mysql_errno($connection) . " error: " . mysql_error($connection) . ".");
$specials_query_count = mysql_numrows($specials_result);
if ($specials_query_count > 0) {
$specials = mysql_fetch_array($specials_result);
$specials['specials_new_products_price'] = tep_round($specials['specials_new_products_price'], 2);
$row['products_price'] = $specials['specials_new_products_price'];
}
}
if ($pricing_add_vat == 1) {
$temp_tax = ($row['products_price'] / 100) * $pricing_vat_rate;
$temp_tax = tep_round($temp_tax, 2);
$row['products_price'] = $row['products_price'] + $temp_tax;
}
// search and replace characters from data which xml will not process
if ($product_name == 1) {
$row['products_name'] = ereg_replace ("&", " and ", $row['products_name']);
$row['products_name'] = ereg_replace ("®", "(R)", $row['products_name']);
$row['products_name'] = ereg_replace ("™", "(TM)", $row['products_name']);
}
if ($product_manufacturer == 1) {
$row['manufacturers_name'] = ereg_replace ("&", " and ", $row['manufacturers_name']);
$row['manufacturers_name'] = ereg_replace ("®", "(R)", $row['manufacturers_name']);
$row['manufacturers_name'] = ereg_replace ("™", "(TM)", $row['manufacturers_name']);
}

// build nested product element
echo "<" . $xml_tags['product'] ." ITEM='" . $row['products_id'] . "'>";
if ($product_name == "1") { echo '<' . $xml_tags['name'] . '>' . $row['products_name'] . '</' . $xml_tags['name'] . '>'; }
if ($product_price == "1") { echo '<' . $xml_tags['price'] . '>' . $row['products_price'] . '</' . $xml_tags['price'] . '>'; }
if ($product_manufacturer == "1") { echo '<' . $xml_tags['manufacturer'] . '>' . $row['manufacturers_name'] . '</' . $xml_tags['manufacturer'] . '>'; }
if ($product_weight == "1") { echo '<' . $xml_tags['weight'] . '>' . $row['products_weight'] . '</' . $xml_tags['weight'] . '>'; }
if ($product_model == "1") { echo '<' . $xml_tags['model'] . '>' . $row['products_model'] . '</' . $xml_tags['model'] . '>'; }
if ($product_quantity == "1") { echo '<' . $xml_tags['quantity'] . '>' . $row['products_quantity'] . '</' . $xml_tags['quantity'] . '>'; }
if ($product_info_link == "1") {
if ($catalog_folder == "") { echo '<' . $xml_tags['url'] . '>http://' . $domain_name . '/product_info.php?products_id=' . $row['products_id'] . '</' . $xml_tags['url'] . '>'; }
else { echo '<' . $xml_tags['url'] . '>http://' . $domain_name . '/' . $catalog_folder . '/product_info.php?products_id=' . $row['products_id'] . '</' . $xml_tags['url'] . '>'; }
}
if ($product_image == "1") {
if ($catalog_folder == "") { echo '<' . $xml_tags['image_url'] . '>http://' . $domain_name . '/' . $image_folder . '/' . $row['products_image'] . '</' . $xml_tags['image_url'] . '>'; }
else { echo '<' . $xml_tags['image_url'] . '>http://' . $domain_name . '/' . $catalog_folder . '/' . $image_folder . '/' . $row['products_image'] . '</' . $xml_tags['image_url'] . '>'; }
}
if ($product_date_added == "1") { echo '<' . $xml_tags['added'] . '>' . $row['products_date_added'] . '</' . $xml_tags['added'] . '>'; }
if ($product_date_modified == "1") { echo '<' . $xml_tags['modified'] . '>' . $row['products_last_modified'] . '</' . $xml_tags['modified'] . '>'; }
if ($product_date_available == "1") { echo '<' . $xml_tags['available'] . '>' . $row['products_date_available'] . '</' . $xml_tags['available'] . '>'; }
//------------------------------------------------------------------- ---------------------------
// START -> insert any extra custom tags here
//------------------------------------------------------------------- ---------------------------

//------------------------------------------------------------------- ---------------------------
// END -> insert any extra custom tags here
//------------------------------------------------------------------- ---------------------------
echo '</' . $xml_tags['product'] . '>';
}
}
// free resources and close connection
mysql_free_result($product_query_result);
mysql_close($connection);
if ($show_creation_time == 1) { echo '</' . $xml_tags['time'] . '>';}
echo '</' . $x
Casero
Profil
prem
Proč by to nešlo? Xml soubor vytvoříš stejně jako textový, není to žadný speciální formát.
prem
Profil *
Díky za rady, vyzkouším ....

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm: