-1
 array(10) {
  ["table_name"]=>
  string(0) ""
  ["chart_type"]=>
  string(5) "Table"
  ["chart_name"]=>
  string(9) "Veterans "
  ["dashboard_name"]=>
  string(7) "Default"
  ["data_option"]=>
  string(0) ""
  ["limit_value"]=>
  string(1) "0"
  ["view_status"]=>
  bool(true)
  ["view_priority"]=>
  string(0) ""
  ["chart_data"]=>
  array(72) {
    [0]=>
    array(11) {
      [0]=>
      string(4) "Rank"
      [1]=>
      string(6) "Branch"
      [2]=>
      string(12) "Level 3 Name"
      [3]=>
      string(12) "Level 4 Name"
      [4]=>
      string(23) "Logged Premia Score MTD"
      [5]=>
      string(26) "Converted Premia Score MTD"
      [6]=>
      string(21) "Persistancy Score MTD"
      [7]=>
      string(23) "Logged Premia Score YTD"
      [8]=>
      string(26) "Converted Premia Score YTD"
      [9]=>
      string(21) "Persistancy Score YTD"
      [10]=>
      string(5) "Score"
    }
    [1]=>
    array(11) {
      [0]=>
      float(1)
      [1]=>
      string(22) " GWALIOR DIRECTSegment"
      [2]=>
      string(29) "G00563 - GOVIND SINGH KUSHWAH"
      [3]=>
      string(21) "S03643 - Shishir Jain"
      [4]=>
      float(1)
      [5]=>
      float(1)
      [6]=>
      float(1)
      [7]=>
      float(0.9994)
      [8]=>
      float(1)
      [9]=>
      float(1)
      [10]=>
      float(9.89901)
    }
    [2]=>
    array(11) {
      [0]=>
      float(2)
      [1]=>
      string(26) " KURUKSHETRA DIRECTSegment"
      [2]=>
      string(23) "A02311 - Amarjeet Singh"
      [3]=>
      string(21) "S00927 - Sachin Kumar"
      [4]=>
      float(1)
      [5]=>
      float(1)
      [6]=>
      float(1)
      [7]=>
      float(0.953)
      [8]=>
      float(1)
      [9]=>
      float(1)
      [10]=>
      float(9.82245)
    }

  }
  ["color_scheme_name"]=>
  string(7) "Default"
}

How do i display the chart_data in php

      $arr=json_decode($row[0],TRUE);

         var_dump($arr);

         foreach($arr as $row)
{
       foreach($row['chart_data'] as $k)
       {
             echo $k['Rank'];
             echo $k['Branch'];
       }
}

EDIT:

for ($x=0; $x<=count
($arr['chart_data']); $x++) {

foreach($arr['chart_data'][$x] as $key=>$val)
{


  echo $val;
}
}
4
  • 7
    format the array please. Commented May 19, 2014 at 8:40
  • ?><pre><?php var_dump($arr); ?></pre><?php Commented May 19, 2014 at 8:45
  • 2
    That's not readable it doesn't even indent. Commented May 19, 2014 at 8:46
  • Have edited my question Commented May 19, 2014 at 9:25

2 Answers 2

1

You are having 2 foreach calls.

The first one passes all keys of the outer array, amongst which chart_data.

The second one looks at the children of the outer array, and looks for chart_data in each child. But is obviously not finding any.

Change your code to this:

$arr=json_decode($row[0],TRUE);
foreach($arr['chart_data'] as $k){
    echo $k['Rank'];
    echo $k['Branch'];
}

edit:

I see. (Thanks for indenting your array) Your problem is off course that $arr['rank']and $arr['branch'] don't exist. They are mere strings inside $k[0] and $k[1] and themselves don't contain any other data.

What would you have like to see outputted?

Sign up to request clarification or add additional context in comments.

Comments

0

Maybe this is solution.

$arr = json_decode($row[0],TRUE);

foreach($row['chart_data'] as $chart_data)
{
    foreach($chart_data[0] as $k)
    {
        echo $k['Rank'];
        echo $k['Branch'];
    }
}

Update :

Rank, Branch is values. Your array is bad format.

$arr = json_decode($row[0],TRUE);

foreach($row['chart_data'] as $chart_data)
{
    foreach($chart_data[0] as $k)
    {
        echo $k[0];
        echo $k[1];
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.