Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 492405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T02:06:32+00:00 2026-05-13T02:06:32+00:00

I’m currently using Fusioncharts Free in my project which requires XML to be in

  • 0

I’m currently using Fusioncharts Free in my project which requires XML to be in a specific format, both for the display of data and for the appearance of the chart.

I have a PHP file called webservice.php which has many similar repetitions of the below:

$address = $_SERVER['PHP_SELF'];

...

if ($address == 'webService.php/fcf/last5pricechanges/'){
//query MySQL DB and build up XML string in $output variable to output to browser
//building up each line of XML more or less line by line
}

The outputted XML may look like so:

<graph caption="Active Items - Grouped by Site" showNames="1" decimalPrecision="0" bgcolor="eeeeee">
<set name="xyz.co.uk" value="1"/>
<set name="abc.com" value="5"/>
</graph>

It’s becoming a bit of a maintenance nightmare to update this code, yet afaik it wouldn’t be possible to transfer data using a standard format – such as REST, as Fusioncharts requires specific XML properties. Are there better ways to handle the above? Can I improve the modularity and maintainability of my code easily?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T02:06:32+00:00Added an answer on May 13, 2026 at 2:06 am

    I’ve got a couple of ideas you could consider.

    #1
    Using a template engine, like Smarty, would probably make this a little easier to maintain. It would at least get rid of the XML from your PHP code.

    For example, you could create a template for the XML snippet you posted:

    <?xml version="1.0" encoding="UTF-8" ?>
    {foreach from=$graphs item=graph}
        <graph caption="{$graph.caption}" showNames="{$graph.show_names}" decimalPrecision="{$graph.decimal_precision}" bgcolor="{$graph.bg_color}">
        {foreach from=$graph.set item=set}
            <set name="{$set.name}" value="{$set.value}"/>
        {/foreach}
        </graph>
    {/foreach}
    

    And call it from PHP as

    <?php
    $address = $_SERVER['PHP_SELF'];
    
    $smart = new Smarty();
    $graphs = array();
    
    if ($address == 'webService.php/fcf/last5pricechanges/')
    {
        $graph_result = mysql_query("SELECT caption, show_names, decimal_precision, bg_color
                                     FROM graph WHERE something='something else'");
        while($graph_row = mysql_fetch_assoc($graph_result))
        {
            $graph_row;
            $set_result = mysql_query("SELECT name, value FROM set WHERE graph_id = {$graph_row['id']}");
            while($set_row = mysql_fetch_assoc($set_result))
            {
                $graph_row['sets'][] = $set_row;
            }
            $graphs[] = $graph_row;
        }
    }
    
    $smarty->assign('graphs', $graphs);
    $smarty->display('graph_template.tpl');
    ?>
    

    #2
    You could create objects to help you manage the code. For example, to generate the same XML output as before, you could do:

    <?php
    class Graph
    {
        protected $caption;
        protected $show_names;
        protected $decimal_precision;
        protected $bg_color;
    
        protected $sets;
    
        public function __construct($graph_id)
        {
            $graph_result = mysql_query("SELECT caption, show_names, decimal_precision_bg_color
                                     FROM graph WHERE something='something else'");
            while($graph_row = mysql_fetch_assoc($graph_result))
            {
                list($this->caption, $this->show_names, $this->decimal_precision, $this->bg_color) = $graph_result;
                $set_result = mysql_query("SELECT name, value FROM set WHERE graph_id = {$graph_row['id']}");
                while($set_row = mysql_fetch_assoc($set_result))
                {
                    $this->sets[] = $set_row;
                }
            }
        }
    
        public function fetch_xml()
        {
            $output  = '<?' . 'xml version="1.0" encoding="UTF-8" ?' . '>';
            $output .= "<graph caption=\"{$this->caption}\" showNames=\"{$this->show_names}\" decimalPrecision=\"{$this->decimal_precision}\" bgcolor=\"{$this->bg_color}\">\n";
            foreach($this->sets as $set)
            {
                $output .= "<set name=\"{$set->name}\" value=\"{$set->value}\"/>\n";
            }
            $output .= "</graph>";
            return $output;
        }
    }
    ?>
    

    And call it in your main code like:

    <?php
    $address = $_SERVER['PHP_SELF'];
    if ($address == 'webService.php/fcf/last5pricechanges/')
    {
        $graph = new Graph(1);
        echo $graph->fetch_xml();
    }
    ?>
    

    #3
    You could try using something like SimpleXML, but I doubt that would help much with the maintainability, as it would be just as verbose as the echo method

    And #4
    … nope, I’m all out 🙂
    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
In my XML file chapters tag has more chapter tag.i need to display chapters
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I am using jsonparser to parse data and images obtained from json response. When
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using JSon response to parse title,date content and thumbnail images and place
I used javascript for loading a picture on my website depending on which small
I want use html5's new tag to play a wav file (currently only supported
I would like to run a str_replace or preg_replace which looks for certain words

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.