Adding commas to a loop within a loop
<p>I'm trying to create a list using a loop within a loop. I have 3 tables. </p>

<p>T1: faculty
T2: keywords
T3: facID, keywordID</p>

<p>I've created a select statement to cross join the rows and spit out something like this:</p>

<pre><code>Faculty Name A
keyword-a keyword-b keyword-c

Faculty Name B
keyword-a keyword-d keyword-f
</code></pre>

<p>Everything works great except I need to add commas to the keyword list and my code isn't doing the trick. My keywords are still looping through without the comma.</p>

<pre><code> &lt;?php while ($row = mysql_fetch_assoc($result)) { ?&gt;

 &lt;?php if ($row['facID'] !== $lastID ) { ?&gt;
&lt;?php echo $row['facname']; ?&gt;&lt;br /&gt;
    &lt;?php $lastID = $row['facID'];  ?&gt; 
 &lt;?php }  ?&gt;

 &lt;?php $kwords = array();
foreach($row as $k =&gt; $v) {
     if (strpos($k, 'kword') === 0) {
     $kwords[] = $v;
     }
  } 
  echo implode(', ', $kwords);

  }  ?&gt;
</code></pre>

<p>Any suggestions? I'm a noob and I'm hoping it's something very obvious!</p>
