How to remove last character from a string inside a loop
<p>I am trying to print the different category's selected in a single line in xml,
like</p>

<pre><code>&lt;cat_name&gt;meeting, food and drinks, sports&lt;/cat_name&gt;
</code></pre>

<p>The output I am getting:</p>

<pre><code>&lt;cat_name&gt;meeting, food and drinks, sports,&lt;/cat_name&gt; 
</code></pre>

<p>I want to remove only the last comma.</p>

<p>The code I have written so far is:</p>

<pre><code>$sq="
    select category_main.cat_name
    from category_main
    join category 
        on(category.cat_id=category_main.cat_id)
    where category.event_id='$event_id'
";
$e=mysql_query($sq);

$xml ='&lt;cat_name&gt;';
while($row=mysql_fetch_array($e))
{
    $res=$row['cat_name'];

    //$new = substr($val,0,-1);
    $xml .="$res, ";                
}

$xml .='&lt;/cat_name&gt;';
echo $xml;
</code></pre>
