title: PHP Array Issue 'Illegal string offset'
body: <p>I am trying to create a navigation menu from a MySQL database.I have this code that takes the results array of a mysql query ($row) and puts them in ($item). When I process each of the $items, I am getting these warnings:</p>
  
  <blockquote>
    <p><strong>Warning:</strong> Illegal string offset 'parent_id' in C:\xampp\htdocs\bootstrap\includes\navigation.php on line 52
    Warning: Illegal string offset 'parent_id' in C:\xampp\htdocs\bootstrap\includes\navigation.php on line 52
    <strong>Warning:</strong> Illegal string offset 'page' in C:\xampp\htdocs\bootstrap\includes\navigation.php on line 53</p>
  </blockquote>
  
  <p>I have tried to change <code>$item['id']</code>, <code>$item['page']</code>, and <code>$item['parent_id']</code> to <code>$item[0]</code>, <code>$item[1]</code>, and <code>$item[2]</code> respectively and this did not work either. I have roamed Google trying to see what else to do. This code is borrowed from a solution that is working here: </p>
  
  <p><a href="http://www.websitesdevelopments.com/blog/post/dynamic-multilevel-css-drop-down-menu-using-css-php-and-mysql" rel="nofollow">http://www.websitesdevelopments.com/blog/post/dynamic-multilevel-css-drop-down-menu-using-css-php-and-mysql</a></p>
  
  <p>But I don't know why it isn't working for me.</p>
  
  <pre><code>&lt;?php
  include("includes/database.php");
  
  try {
      // read all pages from the database     
      $query = "SELECT * FROM pages";     
  
      // prepare query statement
      $stmt = $con-&gt;prepare( $query );
  
      // execute query
      $stmt-&gt;execute();
  
      //count the number of pages
      $num = $stmt-&gt;rowCount();
  
      //put results array into variable
      $rows = $stmt-&gt;fetch(PDO::FETCH_ASSOC);
  
  }catch(PDOException $e) { 
      //something wrong with query/datbase connection
      echo $e-&gt;getMessage();
  }
  
  ?&gt;
  
   &lt;?php
       $items = $rows;
       $id = '';
       print_r($items);
  
      foreach($items as $item){
        if($item['parent_id'] == 0){
            echo "&lt;li&gt;&lt;a href='#'&gt;".$item['page']."&lt;/a&gt;";
            $id = $item['id'];
            sub($items, $id);
            echo "&lt;/li&gt;";
        }
      }
       echo "&lt;/ul&gt;";
  
      function sub($items, $id){
          echo "&lt;li class='dropdown'&gt;";
          echo "&lt;a href='#' class='dropdown-toggle' data-toggle='dropdown'&gt;Portfolio &lt;b class='caret'&gt;&lt;/b&gt;&lt;/a&gt;";
          echo "&lt;ul class='dropdown-menu'&gt;";
          foreach($items as $item){
              if($item['parent_id'] == $id){
                  echo "&lt;li&gt;&lt;a href='?page=".$item['page']."'&gt;".$item['page']."&lt;/a&gt;";
                  sub($items, $item['id']);
                  echo "&lt;/li&gt;";
              }
          }
          echo "&lt;/ul&gt;";
      }
  
       ?&gt;
  </code></pre>