Title: Include PHP with multiple outputs
Last modified: August 30, 2016

---

# Include PHP with multiple outputs

 *  [Aleharu](https://wordpress.org/support/users/aleharu/)
 * (@aleharu)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/include-php-with-multiple-outputs/)
 * I know how to include a PHP file that returns and array using ‘echo’ and JQuery
   but I want to include a PHP with multiple outputs (I can define the outputs in
   JavaScript inside the PHP file)
 * Is it possible? I have tried to include it in resources, but it doesn’t work.
 * [https://wordpress.org/plugins/amcharts-charts-and-maps/](https://wordpress.org/plugins/amcharts-charts-and-maps/)

Viewing 5 replies - 1 through 5 (of 5 total)

 *  Plugin Author [martynasma](https://wordpress.org/support/users/martynasma/)
 * (@martynasma)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/include-php-with-multiple-outputs/#post-6702899)
 * Do you mean you want to load the data generated by some PHP file and use it as
   a data provider for the chart?
 * In that case I suggest you use the Data Loader plugin.
 * Here’s more info about it:
 * [http://www.amcharts.com/tutorials/using-data-loader-plugin/](http://www.amcharts.com/tutorials/using-data-loader-plugin/)
 *  Thread Starter [Aleharu](https://wordpress.org/support/users/aleharu/)
 * (@aleharu)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/include-php-with-multiple-outputs/#post-6702902)
 * No, I just want to load the PHP file and use some variables…
 * In my PHP file I’m calculating an average according to a ‘fixedValue’ and I return
   multiple arrays:
 *     ```
       <?php
       $connection = mysql_connect(*,*,*) or die(mysql_error());
       $database = mysql_select_db(*) or die(mysql_error());
   
       $query = "SELECT * FROM *";
       $result = mysql_query($query);
   
       $mean = array(0,0,0,0,0,0,0);
       $mean2 = array(0,0,0,0,0);
       $count = array(0,0,0,0,0,0,0);
       $count2 = array(0,0,0,0,0);
   
       while($row = mysql_fetch_array($result)){
           for($i = 0;  $i < count($mean); $i++){
             if ($row[Col1]==$i && $row[Col2]=='fixedValue'){
               $mean[$i]=($mean[$i]*$count[$i]+$row[Col3])/($count[$i]+1);
               $count[$i]++;
             }
          }
          for($i = 0;  $i < count($mean2); $i++){
             if ($row[Col4]==$i && $row[Col2]=='otherFixedValue'){
               $mean2[$i]=($mean2[$i]*$count2[$i]+$row[Col3])/($count2[$i]+1);
               $count2[$i]++;
             }
          }
       }
   
       ?>
       <script>
       var mean1 = [<?php echo '"'.implode('","', $mean).'"' ?>];
       var mean2 = [<?php echo '"'.implode('","', $mean2).'"' ?>];
       </script>
       ```
   
 * So, I want to include same PHP file and use vars mean1 and mean2
 *  Plugin Author [martynasma](https://wordpress.org/support/users/martynasma/)
 * (@martynasma)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/include-php-with-multiple-outputs/#post-6702909)
 * Well, you can’t include PHP code into chart, if that’s what you need. Even if
   we could make it work, it would be awfully unsecure to allow PHP code to be added
   via admin interface directly.
 * I suppose you would need to add that functionality to your WP theme or create
   a standalone WP plugin for that.
 *  Thread Starter [Aleharu](https://wordpress.org/support/users/aleharu/)
 * (@aleharu)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/include-php-with-multiple-outputs/#post-6702910)
 * But I turned PHP array into JavaScript array, is there a way to include the JavaScript
   code?
 *  Plugin Author [martynasma](https://wordpress.org/support/users/martynasma/)
 * (@martynasma)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/include-php-with-multiple-outputs/#post-6702912)
 * Sure. You can copy and paste the JavaScript output into the chart code.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Include PHP with multiple outputs’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/amcharts-charts-and-maps_6f74b0.svg)
 * [amCharts: Charts and Maps](https://wordpress.org/plugins/amcharts-charts-and-maps/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/amcharts-charts-and-maps/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/amcharts-charts-and-maps/)
 * [Active Topics](https://wordpress.org/support/plugin/amcharts-charts-and-maps/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/amcharts-charts-and-maps/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/amcharts-charts-and-maps/reviews/)

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * 5 replies
 * 2 participants
 * Last reply from: [martynasma](https://wordpress.org/support/users/martynasma/)
 * Last activity: [10 years, 5 months ago](https://wordpress.org/support/topic/include-php-with-multiple-outputs/#post-6702912)
 * Status: not resolved