Jump to content

Storing array data into mysql table How help


Mancent

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] => [email protected]
)

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?

 



 

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,

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.