appendChild($Raport); $UltimaLuna= $xml->createElement("Ulti-6ren">
gpt4 book ai didi

php - 使用 PHP 使用 mysql pdo 中的数据生成 XML

转载 作者:行者123 更新时间:2023-11-29 11:27:40 24 4
gpt4 key购买 nike

<?php

$xml=new DomDocument("1.0", "UTF-8");

session_start();
require("Connection.php");

$ses = $_SESSION['user'];

$Raport= $xml->createElement("Raport");
$Raport= $xml->appendChild($Raport);

$UltimaLuna= $xml->createElement("UltimaLuna");
$UltimaLuna=$Raport->appendChild($UltimaLuna);

$sql=$conn->prepare("SELECT Sum FROM Operations WHERE Type='Expense' AND ID_User = (SELECT ID_User FROM Users WHERE Email = '$ses') ");
$sql->execute();
$Suma = $sql->fetchAll(PDO::FETCH_ASSOC);

foreach ($Suma as $row)
$TotalS = $TotalS + $row["Sum"];

echo "$TotalS";

$sql = $conn->prepare("SELECT categoryName FROM Categories WHERE Type='Expense' AND ID_User = (SELECT ID_User FROM Users WHERE Email = '$ses')");
$sql->execute();
$result = $sql->fetchAll();
foreach ($result as $row) {
print '<option value="'.$row['categoryName'].'">'.$row['categoryName'].'</option>';
echo "<p>".$row['categoryName']."</p>";
$Categorie=$xml->createElement('"'.$row['categoryName'].'"');
$Categorie=$UltimaLuna->appendChild($Categorie);
$Suma=$xml->createElement("Suma","$100");
$Suma=$Categorie->appendChild($Suma);
}
print '</select>';

$Total=$xml->createElement("Total");
$Total=$UltimaLuna->appendChild($Total);
$Suma=$xml->createElement("Suma",'$TotalS');
$Suma=$Total->appendChild($Suma);

$Categorie=$xml->createElement( "Categorii");
$Categorie=$UltimaLuna->appendChild($Categorie);
$Suma=$xml->createElement("Suma",'$TotalS');
$Suma=$Categorie->appendChild($Suma);

$xml->FormatOutput=true;
$string_value=$xml->saveXML();
$xml->save("example.xml")

?>

我想用 PHP 生成一个 XML...我在 MySQLCategories(CategoryName..) 中有一个,我想为每个类别(假期、学校等)显示一个新的子类别。在 $TotalS 中,我计算类别的 SUM ,但是当我想附加到 Sum 值时,它不起作用......我真的很感谢你的帮助!提前致谢

最佳答案

改变

$Suma=$xml->createElement("Suma",'$TotalS');

$Suma=$xml->createElement("Suma",$TotalS); // or $Suma=$xml->createElement("Suma","$TotalS");

查看差异:https://eval.in/592177

了解单引号 ' 和双引号 "

https://stackoverflow.com/a/3446286/2815635

关于php - 使用 PHP 使用 mysql pdo 中的数据生成 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37923751/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com