View Full Version : implode help

08-11-2008, 07:24 AM
I'm making a small script where a user can favorite an item and add it to their list of favorites. In the user table, I have a column called 'favorites'. That's where the item IDs will be stored, separated with a comma. So if a user clicks on the "Favorite" button, here's how it should work:

1. Select the list of favorite items from the column
2. Explode the comma and place the IDs in an array
3. Add the pic ID (the one that was just favorited) into the end of the array
4. Implode a comma between each ID
5. Insert the new result back into the column

$pic = mysql_real_escape_string($_GET['picid']);
$result = mysql_query("SELECT favorites FROM user WHERE usrname = '" . $username . "'");
$row = mysql_fetch_array($result);
$favorites = explode(",", $row['favorites']);
array_push($favorites, $pic);

That's what I came up with so far. I just don't know how to implode a comma in between the IDs again.

08-11-2008, 01:33 PM
implode(",", $favourites);

08-11-2008, 05:19 PM
Oh I'm stupid. I don't know how I didn't come up with that before. Thanks!