+ Post New Thread
Results 1 to 2 of 2
Coding Thread, [PHP] - Creating Dataset from an Array. in Coding and Web Development; Once again, I bow to the superior knowledge of those on Edugeek! Another PHP, MySQL problem; I'm trying to produce ...
  1. #1
    FragglePete's Avatar
    Join Date
    Feb 2008
    Location
    Wiltshire
    Posts
    513
    Blog Entries
    25
    Thank Post
    133
    Thanked 66 Times in 57 Posts
    Rep Power
    24

    [PHP] - Creating Dataset from an Array.

    Once again, I bow to the superior knowledge of those on Edugeek!

    Another PHP, MySQL problem; I'm trying to produce a Dataset to use within FusionCharts for a project I'm working on, from a query on a MySQL database. The query is sound, and gives the results I need based on various session variables, but it's this bit I'm struggling with...

    Code:
    $strXML = "<chart caption='Date Range Data from Sensor' showAnchors='0' showValues='0' showBorder='1' formatNumberScale='0' lineThickness='2' lineColor='0000FF' xAxisName='Date & Time' yAxisName='Sensor Reading' >";
    
    //Use the SQL Statement created in MM
    
    $query2 = $rsSensorDataRange; //call string query
    
    $strCategories = "<categories>"; //create categories
    while ($cat = mysql_fetch_array($query2, MYSQL_ASSOC))
    
    {
    $strCategories .= "<category label='" . $cat['TimeOfDay'] . "' />"; //display categories
    }
    $strCategories .= "</categories>";
    
    
    $strValues = "<dataset seriesName='Sensor Value'>"; //create values
    while ($vals = mysql_fetch_array($query2, MYSQL_ASSOC))
    {
    $strValues .= "<set value='" . $vals['Value'] . "' />"; //display values
    }
    $strValues .= "</dataset>";
    
    //Close the Chart XML String
    $strXML .= $strCategories . $strValues . "</chart>";
    //Render the Chart
    echo renderChart("FusionChartsXT/ZoomLine.swf", "", $strXML, "SensorReading", 790, 400, false, true);
    The thing works to a point, the first part of the dataset gets created (ie. The Categories), but for some reason the second part (ie. the values) doesn't. I get the opening and closing dataset, but it just refuses to output anything. It seems that the fetch_array gets killed off while the first while bit.

    I've been staring at this for hours trying to work out why it isn't working! Please help!

    Cheers

    Pete

  2. IDG Tech News

  3. #2
    FragglePete's Avatar
    Join Date
    Feb 2008
    Location
    Wiltshire
    Posts
    513
    Blog Entries
    25
    Thank Post
    133
    Thanked 66 Times in 57 Posts
    Rep Power
    24
    I think I've sussed it. I'm still learning, but the code looks like this now at it appears to work:

    Code:
    <?php
    
    
    $strXML = "<chart caption='Date Range Data from Sensor' showAnchors='0' showValues='0' showBorder='1' formatNumberScale='0' lineThickness='2' lineColor='0000FF' xAxisName='Date & Time' yAxisName='Sensor Reading' >";
    
    //Use the SQL Statement created in MM
    $query2 = $rsSensorDataRange; //call string
    $strCategories = "<categories>"; //create categories
    $strValues = "<dataset seriesName='Sensor_Value'>"; //create data series for Values
    while ($cat = mysql_fetch_array($query2, MYSQL_ASSOC))
    {
    $strCategories .= "<category label='" . $cat['TimeOfDay'] . "' />"; //display categories from 'TimeOfDay' field
    $strValues .= "<set value='" . $cat['Value'] . "' />"; //display Values from 'Value' field
    }
    
    $strCategories .= "</categories>";
    $strValues .= "</dataset>";
    
    //Close the Chart XML String
    $strXML .= $strCategories . $strValues . "</chart>";
    //Render the Chart
    echo renderChart("FusionChartsXT/ZoomLine.swf", "", $strXML, "SensorReading", 790, 400, false, true);
    ?>

SHARE:
+ Post New Thread

Similar Threads

  1. Replies: 4
    Last Post: 20th November 2011, 12:53 PM
  2. Best program to create time lapse movie from an AVI file?
    By tech_guy in forum How do you do....it?
    Replies: 0
    Last Post: 10th May 2010, 11:26 AM
  3. PHP: Extracting data from a SQL generated array
    By BarryWAaMC in forum Coding
    Replies: 15
    Last Post: 27th March 2010, 08:27 PM
  4. Extracting data from an MIS
    By MikeBostock in forum MIS Systems
    Replies: 76
    Last Post: 27th February 2008, 10:18 PM
  5. Removing blu-tack from an optical mouse
    By indiegirl in forum Hardware
    Replies: 13
    Last Post: 7th June 2006, 05:50 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •