title: How to change "while" loop to a "foreach" loop
body: <p>I would like to ask a question about "foreach loop" in PHP. Towards the bottom of the code below, the "while" loop accesses elements from an array individually. How can I rewrite the BODY of the while loop using a "foreach" loop?  </p>
  
  <pre><code>  &lt;?php
    require_once('MDB2.php');
    $db = MDB2::connect("mysql://mk:mk@shark.company.com/mk");
    if(PEAR::iserror($db)) die($db-&gt;getMessage());
    $sql = "SELECT courses.ID,courses.Name,staff.Name
    FROM courses,staff
    WHERE courses.Coordinator=staff.id
    and courses.ID = \"$course\"";
    $q = $db-&gt;query($sql);
    if(PEAR::iserror($q)) die($q-&gt;getMessage());
    while($row = $q-&gt;fetchRow()){
    echo "&lt;tr&gt;&lt;td&gt;$row[0]&lt;/td&gt;\n";
    echo "&lt;td&gt;$row[1]&lt;/td&gt;\n";
    echo "&lt;td&gt;$row[2]&lt;/td&gt;&lt;/tr&gt;\n";
    }
    }
    ?&gt;
   &lt;/table&gt;
   &lt;/body&gt;&lt;/html&gt;
  </code></pre>