abch624 Posted July 6, 2008 Share Posted July 6, 2008 Hi guys I have a field in the database that stores details of where users have visited. In the database this is stored as a long string for instance "France|Sweden|United Kingdom|United States|". The field is called "countries". I want to retrive this field for all users and create a long array with all these countries.... Now what I mean is this If there are two users whose countries field in the database is "France|Sweden|United Kingdom|United States|" and "India|South Africa|United Kingdom|United States|" I would like the array to be something like this: (France, Sweden, United Kingdom, United States, France, Sweden, United Kingdom, United States,) Now the code I have is something like this $query = "SELECT countries AS tag FROM profiledetails"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { $country = $row['tag']; $countries = explode('|', $country); $count = ""; foreach ($countries as $countnew) { $count = $count.", ".$countnew; } } Now what happens in this is that the last entry from the database is stored. But I would like all these entries to add up as an array as I mentioned b4. Pls Help guys Link to comment https://forums.phpfreaks.com/topic/113478-solved-php-loop-create-a-long-array/ Share on other sites More sharing options...
trq Posted July 6, 2008 Share Posted July 6, 2008 $count .= $count.", ".$countnew; Link to comment https://forums.phpfreaks.com/topic/113478-solved-php-loop-create-a-long-array/#findComment-583080 Share on other sites More sharing options...
abch624 Posted July 6, 2008 Author Share Posted July 6, 2008 Thanks but that was not how... I figured it out anyways thanks a lot The new code is like this now $query = "SELECT countries AS tag FROM profiledetails"; $result = mysql_query($query); $count = array(); while ($row = mysql_fetch_array($result)) { $country = $row['tag']; $countries = explode('|', $country); $count = array_merge($countries, $count); } so basically merging arrays..... thanks Link to comment https://forums.phpfreaks.com/topic/113478-solved-php-loop-create-a-long-array/#findComment-583093 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.