<?php
require("phpsqlajax_dbinfo.php");
$dom = new DOMDocument("1.0");
$dp = fopen('samp.xml', 'w');
$node = $dom->createElement("Groceries");
fwrite($dp, '$node');
$parnode = $dom->appendChild($node);
$connection = mysql_connect($host, $user, $pass);
if (!$connection) {
die('Not connected : ' . mysql_error());
}
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
die ('Can\'t use db : ' . mysql_error());
}
$query = "SELECT * FROM tbl_groceryitem";
$result = mysql_query($query);
if (!$result) {
die('Invalid query: ' . mysql_error());
}
echo "<groceries>";
while ($row = @mysql_fetch_assoc($result)) {
$node = $dom->createElement("item");
echo "<echo>";
fwrite($dp, '$node');
$newnode = $parnode->appendChild($node);
$newnode->setAttribute("auto_id", $row['auto_id']);
echo "<auto_id>", $row[auto_id];
fwrite($dp, '$newnode');
$newnode->setAttribute("Gro_barcode", $row['Gro_barcode']);
echo "<Gro_barcode>", $row[Gro_barcode];
fwrite($dp, '$newnode');
$newnode->setAttribute("Gro_name", $row['Gro_name']);
echo "<Gro_name>", $row[Gro_name];
fwrite($dp, '$newnode');
$newnode->setAttribute("Gro_brand", $row['Gro_brand']);
echo "<Gro_brand>", $row[Gro_brand];
fwrite($dp, '$newnode');
$newnode->setAttribute("Gro_category", $row['Gro_category']);
echo "<Gro_category>", $row[Gro_category];
fwrite($dp, '$newnode');
$newnode->setAttribute("Gro_aisle", $row['Gro_aisle']);
echo "<Gro_category>", $row[Gro_aisle];
fwrite($dp, '$newnode');
$newnode->setAttribute("Gro_qty", $row['Gro_qty']);
echo "<Gro_qty>", $row[Gro_qty];
fwrite($dp, '$newnode');
$newnode->setAttribute("Gro_netwt", $row['Gro_netwt']);
echo "<Gro_netwt>", $row[Gro_netwt];
fwrite($dp, '$newnode');
$newnode->setAttribute("Gro_pic", $row['Gro_pic']);
echo "<Gro_pic>", $row[Gro_pic];
fwrite($dp, '$newnode');
$newnode->setAttribute("Gro_price", $row['Gro_price']);
echo "<Gro_price>", $row[Gro_price];
fwrite($dp, '$newnode');
$newnode->setAttribute("Gro_tax", $row['Gro_tax']);
echo "<Gro_tax>", $row[Gro_tax];
fwrite($dp, '$newnode');
echo "</item>";
fwrite($dp, '</item>');
}
fwrite($dp, '</groceries');
echo $dom->saveXML($xml);
?>
Я новичок в php.
Я создаю php-файл, который может генерировать xml-файл с данными из myPHPAdmin.Спасибо д.Надеюсь, кто-нибудь может мне помочь.
При первой попытке, код был отображен в php, и когда я открываю, чтобы проверить созданный XML.дисплей был '$node
', он отображает точную строку в fwrite, когда я пытаюсь удалить строковую кавычку (''), например, fwrite($dp,$node);
.Я получил ошибку.
И когда я пытаюсь вернуть код в fwrite ($ dp, '$ node') ;.Там не было никакого дисплея.страница XML пуста.