title: How to iterate associative multidimensional array in Javascript/JSON/AJAX with PHP
body: <p>My database results are multidimensional array.
  Here is my code in php file.</p>
  
  <pre><code>$course_detail = array();
  while($row=mysqli_fetch_assoc($result))
  {
     //$course_detail[] = $row;
     $course_detail[ strtoupper($row['course_name'][0]) ][] = array(
      'course_name' =&gt; $row['course_name'],
      'duration' =&gt; $row['duration'],
      'c_desc' =&gt; $row['c_desc']
      );
  }
  echo json_encode($course_detail);
  </code></pre>
  
  <p>And here is my Ajax/Javascript/JSON code.</p>
  
  <pre><code>&lt;script type="text/javascript" &gt;
  function fetch(val) {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
      if(xhttp.readyState == 4 &amp;&amp; xhttp.status == 200) {
          document.getElementById("response").innerHTML = "";
          var j = JSON.parse(xhttp.responseText);
          for (var i = 0; i &lt; j.length; i++) 
              {
                  document.getElementById("response").innerHTML = j[i]['name'] + ' ' + j[i]['duration']+ ' ' +  j[i]['c_desc'] ;
              }
      }
  }
  xhttp.open('get', 'stream-process.php?sname='+val, true);
  xhttp.send();
  }
  </code></pre>
  
  <p>This javascript function is called from submit button with ID of hidden element which is generated dynamically.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>    &lt;form action="" method="get"&gt;
      &lt;?php
          $db_manager = new db_manager();
          $db_manager-&gt;DBLogin();
          $sql = "select * from streams";
          $result=mysqli_query($db_manager-&gt;connection,$sql);
          $counter = 1;
          while($row=mysqli_fetch_array($result))
          {   ?&gt;
              &lt;input type="hidden" id="stream_name&lt;?php echo $counter ?&gt;"  class="stream" name="sname" value="&lt;?php echo $row["scode"]; ?&gt;"&gt;
          &lt;li class="list-group-item"&gt;&lt;input class="form-control" onclick="fetch(document.getElementById('stream_name&lt;?php echo $counter;?&gt;').value)" type="button" id="submit" value="&lt;?php echo $row["name"]; ?&gt;"/&gt;&lt;/li&gt;
          &lt;?php
          $counter++;
          }
          ?&gt;
          &lt;/form&gt;
          &lt;/div&gt;
          &lt;div id="response" class="stream-detail col-sm-8"&gt;
          hey there......
          &lt;/div&gt;
  </code></pre>
  
  <p>when i click on any button, nothing is displaying. It worked correct with Simple multidimensional array. but i want in Associative Multidimensional Array. So that i can treat each field of each row differently.
  Thanks in advance.</p>