CodeIgniter Forums
Loop trough multi dimensional Array correctly for FusionChart - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Loop trough multi dimensional Array correctly for FusionChart (/thread-37323.html)



Loop trough multi dimensional Array correctly for FusionChart - El Forum - 01-05-2011

[eluser]CI_adis[/eluser]
Hi fellow CI-members,

I am testing FusionCharts with Code Igniter (as soon I have a good overview I will try to write an Wiki for it, because there are a lot of incomplete tuts about it!).

But I am also pretty new to PHP so I have some issues with multi dimensional array's!

Consider these two array's:
Code:
$arrData[0][0] = 'Me';
$arrData[1][0] = 'You';
$arrData[2][0] = 'He';
$arrData[3][0] = 'She';

$arrData[0][1] = 12;
$arrData[1][1] = 13;
$arrData[2][1] = 14;
$arrData[3][1] = 6;

should be the same as:

Code:
$arrData = array (12, 13, 14, 6);
$nameData = array ('Me', 'You', 'He', 'She');

The first one would be easy to use in FusionCharts:
Code:
$FC->addChartDataFromArray($arrData);

the second one needs a foreach:
Code:
foreach ( $arrData as $i => $data ) {
         $FC->addChartData ( $data ,"label=" .$nameData[$j]);
     $j+=1;
     $i=0;
         foreach ( $arrData as $i => $data ) {
             $i+=1;
         }
     }

And my question is:
What should i use? (considering performance etc)

If you advice the first one, can you provide an example how to add data from a database?
Because I have no idea how to built the array while fetching records from a database!

Thanks all!


Loop trough multi dimensional Array correctly for FusionChart - El Forum - 01-06-2011

[eluser]Cristian Gilè[/eluser]
Hi CI_adis,

Quote:the second one needs a foreach:
Code:
foreach ( $arrData as $i => $data ) {
         $FC->addChartData ( $data ,"label=" .$nameData[$j]);
     $j+=1;
     $i=0;
         foreach ( $arrData as $i => $data ) {
             $i+=1;
         }
     }

The second foreach is not necessary:
Code:
foreach ( $arrData as $i => $data )
{
         $FC->addChartData ( $data ,"label=" .$nameData[$i]);
}



Loop trough multi dimensional Array correctly for FusionChart - El Forum - 01-06-2011

[eluser]CI_adis[/eluser]
Hi Cristian Gilè,

Thanks, you are right. I do not need the second foreach!

Thanks.

@all:

Still my question is open:

How to add values in a multidimensional array while fetching records from a db?


Loop trough multi dimensional Array correctly for FusionChart - El Forum - 01-06-2011

[eluser]Cristian Gilè[/eluser]
Take a look at this screencast: codeigniter from scratch
It's a good starting point to learn CI.


Loop trough multi dimensional Array correctly for FusionChart - El Forum - 01-06-2011

[eluser]CI_adis[/eluser]
Thanks for pointing me to this site.
I already took lessons 1-6 :-) and achieved pretty nice results with CI.

But now I want to integrate FusionCharts and there many topics about FusionCharts with CI but i you follow "their" examples you run into strange issues. Therefore I'm testing it myself to obtain some good knowledge about it. Besides CI I need training for PHP, so i started reading a lot of E-Books :-)

Later on I will try to write a complete wiki about CI and FusionCharts.

Cheers.