title: sql for loop php only gives me last 3 values in the array
body: <p>So I have taken data from a table and i'm trying to pair the 'main folder' with the 'parent_id' but when I display the results the final array only contains the final three results in the database. I am very very confused.</p>
  
  <p>I have already done this with an array of 'main folder' paired with 'id' for parent_id = 0. It works absolutely fine. I am bamboozled.</p>
  
  <pre><code>//This for loop works absolutely fine
  while($parents[] = mysqli_fetch_array($result)) {
      //Adding values from sql table row by row into parents[]
  }
  
  for($i = 0; $i &lt; (count($parents) - 1); $i++) {
      $ParentsArray[$parents[$i]['mainfolder']] = $parents[$i]['id'];
  }
  
  //Problem starts with this for loop below
  
  while($children[] = mysqli_fetch_array($subResult)) {
      //Adding values from sql table row by row into children[]
  }
  var_export($children);
  
  for($b = 0; $b &lt; (count($children) - 1); $b++) {
      echo $b;
      $ChildrenArray[$children[$b]['mainfolder']] = $children[$b]['id'];
  }
  var_export($ChildrenArray);
  </code></pre>