Sabmin Posted November 7, 2010 Share Posted November 7, 2010 I have a text field in my database that I'm pulling the contents of and parsing into an array, at which point depending on the users action I'm either adding to the end or searching for a specific value and removing it. I'm then converting the array back to a string and placing it back into the text field in the database. Everything works fine except for either an empty array value or a new line forcing its way to the front. Causing, naturally an empty value loaded onto the page that displays this part of the db. While I know theres a couple things in there that aren't necessary I was just too lazy to take them out before posting after attempting to find a way around this problem. But here is the bulk of the code. I appreciate any help! $to_add = "SELECT * FROM teams WHERE name = '$teamname'"; $que_to_add = mysql_query($to_add); while ($fetch_members = mysql_fetch_array($que_to_add, MYSQL_BOTH)) { $members = explode("\n", $fetch_members['members']); $members = array_filter($members); foreach ($members as $key => $value) { $value = trim($value); $new_insert[] = $value; } } $new_insert = array_filter($new_insert); foreach ($new_insert as $key => $value) { if ($value != "") { $to_insert = ($to_insert . "\n" . $value); } } $to_insert = ($to_insert . "\n" . $for_insert); $insert_ready = "UPDATE teams SET members = '$to_insert' WHERE name = '$teamname'"; $insert = mysql_query($insert_ready); Link to comment https://forums.phpfreaks.com/topic/218049-problems-with-an-array-updating-a-db-table/ Share on other sites More sharing options...
sasa Posted November 8, 2010 Share Posted November 8, 2010 just trim $to_insert variable before insert it in db Link to comment https://forums.phpfreaks.com/topic/218049-problems-with-an-array-updating-a-db-table/#findComment-1131668 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.