Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: implode help

  1. #1
    Regular Coder
    Join Date
    Jul 2007
    Posts
    100
    Thanks
    1
    Thanked 0 Times in 0 Posts

    implode help

    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

    PHP Code:
    $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.

  • #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Posts
    1,563
    Thanks
    2
    Thanked 163 Times in 160 Posts
    PHP Code:
    implode(","$favourites); 
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow

  • #3
    Regular Coder
    Join Date
    Jul 2007
    Posts
    100
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Oh I'm stupid. I don't know how I didn't come up with that before. Thanks!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •