+ Reply to Thread
Results 1 to 4 of 4

Thread: Splitting a string and sql insert as array?

  1. #1
    learning_brain is offline x10 Sophmore learning_brain is an unknown quantity at this point
    Join Date
    Apr 2010
    Location
    UK, Midlands
    Posts
    170

    Splitting a string and sql insert as array?

    Splitting a string, based on " " is fairly simple, but how do I store it to a longtext field as an array?

    I need to store a) the string part and b) the order within that string.

    I also then need to be able to call any part of that array from the DB.

    Any ideas?

  2. #2
    lemon-tree's Avatar
    lemon-tree is offline x10 Minion lemon-tree has a spectacular aura about
    Join Date
    Nov 2007
    Posts
    1,420

    Re: Splitting a string and sql insert as array?

    Do you mean you need to store a PHP array in a database? If so, try serialize() and unserialize()

  3. #3
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Splitting a string and sql insert as array?

    The relational model for a sequence is to store the position within the sequence along with the items at that position. With multiple sequences stored in the same table, you'd also have an identifier for the sequence. Depending on your needs, it might make more sense to store the entire sequence in a single column, as lemon-tree suggests.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  4. #4
    learning_brain is offline x10 Sophmore learning_brain is an unknown quantity at this point
    Join Date
    Apr 2010
    Location
    UK, Midlands
    Posts
    170

    Re: Splitting a string and sql insert as array?

    Thanks. This is perfect. After looking through the Serialize details, I have also been able to add multi-dimensional arrays, which I think I'm going to need.

    My only issue now is to add post data to each part of the 1st layer array.... Figuring that out now.

+ Reply to Thread

Similar Threads

  1. Replies: 4
    Last Post: 04-23-2010, 02:38 AM
  2. Splitting result into multiple colunms
    By playminigames in forum Programming Help
    Replies: 6
    Last Post: 10-05-2009, 03:53 PM
  3. Regarding - Splitting PHP Files into Includes
    By TofuBoy in forum Programming Help
    Replies: 6
    Last Post: 04-08-2009, 06:57 AM
  4. Cannot use string offset as an array in...
    By darylcarpo in forum Programming Help
    Replies: 2
    Last Post: 10-28-2008, 11:03 AM
  5. Recursive PHP array to Javascript array/object
    By Veridis in forum Programming Help
    Replies: 0
    Last Post: 04-16-2008, 02:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers