Make use of rtrim()
.
$yourfinaltext = rtrim($yourcommadelimitedstring, ',');
Change your while
like this.
while ($row1=mysql_fetch_array($result1)) {
$gallery .= "'".$row1[0]."',";
$home = "SELECT * FROM chat WHERE chat.from IN ('$gallery')";
}
echo rtrim($gallery,',');