writing XML file from MySQL data - foreach loop?
am 05.11.2009 16:03:25 von David Hine
Dear All
I wish to use java charts to display some time series data that is stored in
a MySQL database. The time series is the evapotranspiration (average value
for each day) at a large banana plantation. This will help guide irrigation.
The java charts use an XML file for the data and the formatting.
I have limited the records to 29 days:
$query = "SELECT DATE_FORMAT(dt, '%d-%m-%Y') AS Day, AVG(ET) as ET FROM
database.tablename WHERE DATE(dt) BETWEEN DATE_SUB(NOW(), INTERVAL 30 DAY)
AND DATE(NOW()) GROUP BY DATE(dt)";
I use a new DomDocument to format the output.
Once I have the structure of the standard part of the document (calling the
chart and giving some parameters to it) I want to have a series of strings
like
1.7
1.8
2.1
etc for 29 times....
For that purpose I wrote:
$row = $doc->createElement( "row" );
$chart_data->appendChild( $row );
$number = $doc->createElement( "number" );
while ($row_etdata = mysql_fetch_array($etdata)){
$row->appendChild( $number );
$txtnode = $doc->createTextNode("$ET");
$number->appendChild($txtnode);
When I run this or a variant, I get for example
29 times /> Half right is still wrong. Have considered serialize but that
has its own complexities.
Your assistance or guidance on solving this would be much appreciated.
thanks
David Hine
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: writing XML file from MySQL data - foreach loop?
am 05.11.2009 16:32:02 von Richard Quadling
2009/11/5 David Hine :
> Dear All
> I wish to use java charts to display some time series data that is stored=
in
> a MySQL database. The time series is the evapotranspiration (average valu=
e
> for each day) at a large banana plantation. This will help guide irrigati=
on.
>
> The java charts use an XML file for the data and the formatting.
>
> I have limited the records to 29 days:
> $query =3D "SELECT DATE_FORMAT(dt, '%d-%m-%Y') AS Day, AVG(ET) as ET FROM
> database.tablename WHERE DATE(dt) BETWEEN DATE_SUB(NOW(), INTERVAL 30 DAY=
)
> AND DATE(NOW()) GROUP BY DATE(dt)";
>
> I use a new DomDocument to format the output.
>
> Once I have the structure of the standard part of the document (calling t=
he
> chart and giving some parameters to it) I want to have a series of string=
s
> like
> Â Â Â Â 1.7
> Â Â Â Â 1.8
> Â Â Â Â 2.1
> Â Â Â Â etc for 29 times....
>
> For that purpose I wrote:
>
> $row =3D $doc->createElement( "row" );
> Â $chart_data->appendChild( $row );
>
> Â $number =3D $doc->createElement( "number" );
> while ($row_etdata =3D mysql_fetch_array($etdata)){
> Â Â $row->appendChild( $number );
> $txtnode =3D $doc->createTextNode("$ET");
> $number->appendChild($txtnode);
>
> When I run this or a variant, I get for example
or
> 29 times /> Half right is still wrong. Have considered serialize but that
> has its own complexities.
>
> Your assistance or guidance on solving this would be much appreciated.
> thanks
> David Hine
>
>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Take a look at http://dev.mysql.com/tech-resources/articles/xml-in-mysql5.1 =
-6.0.html#xml-5.1-exporting
--=20
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=3DZEND002498&r=3D213474=
731
ZOPA : http://uk.zopa.com/member/RQuadling
--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php