$subSelect = "SELECT image_id,image_tag from imagetags where image_id = '$img_image_id'"; $resultSub = mysql_query($subSelect) or die(mysql_error()); $subArray = array(); $tagValue = ''; while($rowSub = mysql_fetch_assoc($resultSub)) $subArray[] = $rowSub; print_r($subArray); foreach ($subArray as $subValue) { $tagValue = $tagvalue." ,".$subValue; } print_r($tagValue);