$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; } for( $i= 0; $i< sizeof($subArray); $i++ ) { foreach ($subArray[$i] as $subValue) { $tagValue = $tagvalue." ,".$subValue; } } print_r($tagValue);