title: While loop together with foreach
body: <p>I'm really stuck trying to resolve what should be quite simple.</p>
  
  <p>I Have this</p>
  
  <pre><code>&lt;?php 
  
  $json = json_decode('{
                        "33540116":
                                   {"person":
                                             {"name":"John", "age":"36"}},
                        "33541502":
                                   {"person":                                                                                      
                                             {"name":"Jack", "age":"23"}}
                       }
          ');
  
   $id = array('33540116', '33541502');
  
  
  foreach($id as $id) {
  
          echo $json-&gt;$id-&gt;person-&gt;{'name'}. '&lt;br /&gt;';
          echo $json-&gt;$id-&gt;person-&gt;{'age'}. '&lt;br /&gt;';
  
  
          }
  ?&gt;
  </code></pre>
  
  <p>So the code is decoding a json string then using foreach to echo each result.</p>
  
  <p>This json file is rather large and I'm only interested in certain records that match the id's stored in a mysql table.</p>
  
  <p>To do this I have replaced the id array string above with mysql select statement.</p>
  
  <pre><code>&lt;?php
  $json = json_decode('{
                        "33540116":
                                   {"person":
                                             {"name":"John", "age":"36"}},
                        "33541502":
                                   {"person":                                                                                      
                                             {"name":"Jack", "age":"23"}}
                       }
          ');
  
  $result = mysql_query("SELECT id FROM people");
  $row = mysql_fetch_array($result);
  
  $id = array($row['id']);
  
  foreach($id as $id) {
  
              echo $json-&gt;$id-&gt;person-&gt;{'name'}. '&lt;br /&gt;';
              echo $json-&gt;$id-&gt;person-&gt;{'age'}. '&lt;br /&gt;';
  
  
              }
  ?&gt;
  </code></pre>
  
  <p>Although this works, it only gives me 1 result. 
  What I really need is to loop through the results.
  Unfortunately I don't know how to construct a while loop together with foreach.</p>
  
  <p>I will greatly appreciate your assistance.</p>
  
  <p>UPDATE (extra question)</p>
  
  <p>Thanks everyone. You have helped me solve the problem.</p>
  
  <p>However, I have another question that relates to this matter.</p>
  
  <p>I mentioned above that I merely wanted to echo the results. 
  But this isn't exactly true.
  What I really want to do is update the same mysql table with the results retreived from the json file.</p>
  
  <p>I have a table called people with fields id, name and age.</p>
  
  <p>How can I update this table with these results?</p>
  
  <p>Thanks again.</p>