title: i need a little help on foreach
body: <p>This is my cats in mysql</p>
  
  <pre><code>cats_id   cats_position   cats_parentid 
  
  1            1&gt;                0
  2            1&gt;2&gt;              1
  3            3&gt;                0
  4            1&gt;2&gt;4&gt;            2
  </code></pre>
  
  <p>and i am trying to create a navigation like: </p>
  
  <p>index > cars > fiat > punto </p>
  
  <p>from</p>
  
  <pre><code>cat=4&amp;parent=2&amp;position=1&gt;2&gt;4&gt;
  </code></pre>
  
  <p>I end up getting:</p>
  
  <p>Index carcarcarcar</p>
  
  <p>and my php knowledge is not enough to finish this code. can you help me please.</p>
  
  <pre><code>&lt;?php
  $position = trim($_GET['position']);
  $pieces = explode("&gt;", $position);
  
  $i=0;
   foreach($pieces as $piece){
   $result = mysql_query("SELECT * FROM cats
   WHERE cats_id='".$pieces[$i]."'");
   while($row = mysql_fetch_array($result))
   {
   $piecesid[$i] = $row['cats_id'];
   $piecesname[$i] = $row['cats_name'];
   $piecesposition[$i] = $row['cats_position'];
   }
   $i++;
   }
   ?&gt;
   &lt;a href="index.php"&gt;Index&lt;/a&gt;
   &lt;?php $i=0; foreach($pieces as $piece){
   if($i=0)
    $parent=0;
   else
    $parent=$placesid[$i-1];
   echo '&lt;a href="cats.php?cat='.$piecesid[$i].'&amp;parent='.$parent.'&amp;position='.$piecesposition[$i].'"&gt;'.$piecesname[$i];
  }
  </code></pre>