The following db/table/record names have been modified for security reasons.
My database has a table called 'necklace'. One of the fields is color_id in which you can list an infinite number of 'color_id's
So for example:
Necklace Table
Code: Select all
Necklace_id | Name | Color_id
5 | Oxyde | 2,5,34,83,23Code: Select all
// Get the necklace details
$sql = "SELECT * FROM necklace WHERE necklace_id='5';
$result = mysql_query ($sql);
$color_array = explode(",", $result['color_id']);
// At this point, $color_array is an array, but I want to add the string $new_color into $color_array. Can't for the life of me figure out how to do this
$color_id = implode(",", $color_array);
// Update necklace record with new color ID.
$sql2 = "UPDATE necklace SET color_id='$color_id' WHERE necklace_id='5'";
$result2 = mysql_query ($sql2);