writing XML file from MySQL data - foreach loop?

View: New views
2 Messages — Rating Filter:   Alert me  

writing XML file from MySQL data - foreach loop?

by David Hine-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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
        <number>1.7</number>
         <number>1.8</number>
         <number>2.1</number>
        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 <number 1.71.71.71.71.7 for
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?

by Richard Quadling :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/11/5 David Hine <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
>        <number>1.7</number>
>         <number>1.8</number>
>         <number>2.1</number>
>        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 <number 1.71.71.71.71.7 for
> 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



--
-----
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=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling

--
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php