$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; } $imageTags[$subArray[$i]['image_id']] = $tagValue; } // the above will give you something like: $imageTags[1] = "white, short hair, dog" $imageTags[2] = "cats" etc Where the numbers are your image_id's