SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: implode()?

  1. #1
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,666
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)

    implode()?

    I'm trying to insert an array into a mysql database
    heres my array
    [amenities] => Array
    (
    [0] => 1
    )

    So I'll use the implode() to convert the array into a comma seperated string
    PHP Code:
    $amenities implode(",",$_POST['amenities[]']); 
    but when I echo that variable, I get nothing.

    Is that right?
    "Oh, and Jenkins--apparently your mother died this morning."

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,245
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    Typo:
    PHP Code:
    $amenities implode(",",$_POST['amenities']); 

  3. #3
    SitePoint Wizard lukeurtnowski's Avatar
    Join Date
    Mar 2003
    Location
    Coronado
    Posts
    1,666
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    oh, got it, just had to remove the [] from the POST variable.
    "Oh, and Jenkins--apparently your mother died this morning."

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,245
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by lukeurtnowski View Post
    oh, got it, just had to remove the [] from the POST variable.
    Yep. Keep in mind although you may put [] in your form name (so it is designated as an array), the post accessor for that element does not contain those characters. You simply reference it by its name without the []

  5. #5
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,053
    Mentioned
    66 Post(s)
    Tagged
    0 Thread(s)
    If you find yourself needing to store an array in a database its advisable to use a child table so that the data stored therein can be searched.

  6. #6
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,245
    Mentioned
    155 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Michael Morris View Post
    If you find yourself needing to store an array in a database its advisable to use a child table so that the data stored therein can be searched.
    If it needs to be searched. No sense in decoupling data that would never be searched on (ie: preference settings).


Bookmarks

Posting Permissions

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