Jump to content

Storing array data into mysql table How help


Mancent
Go to solution Solved by Psycho,

Recommended Posts

Ok I have the following fields set up in my sql table

Id
Name
Pic

email

and the array looks like this
 

Array
(
    [id] => 100001957015772
    [name] => Robert Puckett
    [picture] => Array
        (
            [data] => Array
                (
                    [height] => 0
                    [is_silhouette] => 
                    [url] => https://fbcdn-profile-a.akamaihd.net/hprofile-ak-frc1/t1.0-1/c8.0.50.50/p50x50/10251949_622143917860836_1398143136845301890_s.jpg
                    [width] => 0
                )

        )

    [email] => clarity-understanding@hotmail.com
)

I want to store that array in to MySQL table named user_info but I do not know how! Can you guys help me and teach me how to learn arrays?

 



 

Link to comment
Share on other sites

  • Solution

You don't need to convert the array. Just use the right array field in the right places when creating the query

 

 

$query = "INSERT INTO table_name
              (id, name, email, height, width, url, is_silhouette)
          VALUES
              ('{$array['id']}', '{$array['name']}', '{$array['email']}',
               '{$array['picture']['data']['height']}', '{$array['picture']['data']['width']}',
               {$array['picture']['data']['url']}, {$array['picture']['data']['is_silhouette']})";

 

However, if you have data in an array, you should definitely look into prepared statements where you can pass the array to a function to do the insert. You would need to flatten the array however so the data is not is a sub-array,

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.