简体   繁体   English

尝试在 XML 文档中嵌入 SQL 查询(PHP 变量)的答案

[英]Trying to Embed answer from SQL Query(PHP Variable) in XML doc

Hi So this is my first time posting something here, been working on this for a few days but no luck.嗨,这是我第一次在这里发布内容,已经为此工作了几天但没有运气。 Basically I am querying a database in php, getting my answer but I want to send this answer to an XML file for graph creation.基本上我在 php 中查询数据库,得到我的答案,但我想将此答案发送到 XML 文件以创建图形。 Any help would be greatfully appreciated.任何帮助将不胜感激。

Here is the part of the PHP file with embedded sql that returns variable.这是带有嵌入式 sql 的 PHP 文件的一部分,该部分返回变量。

$result = mysqli_query($con,
"SELECT COUNT(*) as FullCount 
FROM DailyShpm 
WHERE (curr_date between '2013-01-01' and now()- INTERVAL 1 YEAR) 
AND (Product= 'AE')
");

while($row = mysqli_fetch_array($result)) {
echo $row['FullCount'] ;
echo "<- Full results for total AE to date for 2013";
echo "<br>";
echo $row['FullCount'] ;
echo "<br>";


$files ="data.xml";

//load xml object
$xml= simplexml_load_file($files);

//assign value

$xml->set->value = $row['FullCount'];
//$xml->chart ->set = $row['FullCount'];


//store the value into the file
file_put_contents($file, $xml->asXML());
}

Here is what it outputs in the xml file这是它在xml文件中输出的内容

<?xml version="1.0" encoding="ISO-8859-1"?>

<chart caption="Year to Date" xAxisName="Year" yAxisName="Amount of Shipments Air Exports"> 



<set label="2013" value=""><value>7707</value></set> 
<set label="2014" value=""/> 

I need the value of 7707 to be put in the value within set label="2013" value"7707"我需要将 7707 的值放入 set label="2013" value"7707" 内的值中

Thanks in advance提前致谢

Change the following:更改以下内容:

$xml->set->value = $row['FullCount'];

to:到:

$xml->attributes()->value = ((string) $xml->attributes()->value) . $row['FullCount'];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM