How to store multidimensional array in database?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rahulephp
    New Member
    • Sep 2009
    • 59

    How to store multidimensional array in database?

    Hi there,

    can you please help me?

    i have data in array and i want to insert it in a single table.
    structure of table and array to be store is shown below:

    Please let me know how to store this array in database?

    Database Structure:


    array-structure


    database-Browse


    Let me know any solution for this?
    Thanks in anticipation
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Make a different table for temp_property, with primary key as (temp_id, temp_property_i d) using foreign key (temp_id) with fields (name, add, size, price, detail)

    If there's no unique id for every property, then make one.

    Comment

    • rahulephp
      New Member
      • Sep 2009
      • 59

      #3
      Thanks for your reply but i did this in another way using serialize and unserialize

      Solution:

      Code:
      //sample
      $temp1 = serialize ($exarray);
      and then store $temp1 in batabase field.
      (recommend to  keep datatype of that field as text)
      
      While fetching the data, again make it unserialize  
      and you will get your original array
      Like this
      $exarray = unserialize ($temp1);
      thanks again for your time

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        If each property has its own name, ad, size, price & detail (as I suppose), I'd still recommend you to make a different table. You will find it useful later on.

        Comment

        • kovik
          Recognized Expert Top Contributor
          • Jun 2007
          • 1044

          #5
          serialize() and unserialize() are in the language primarily for session handling, so that you can save the $_SESSION array. This can be saved in the database since the $_SESSION array should not be limited in the types of fields that it can have.

          However, for pretty much everything else, this is not the case. Session data is like file data. But, data that has specific properties should be inputted in the database with each property as it's own column and each instance as its own row.


          Otherwise, what is the point of even having columns in database tables?

          Comment

          • rahulephp
            New Member
            • Sep 2009
            • 59

            #6
            I would like to say Thanks to all of you for this great discussion.
            Your replied posts are really very appreciating.

            I think we need to close our discussion here.
            Thanks again

            Comment

            Working...