Mancent Posted April 15, 2014 Share Posted April 15, 2014 Ok I have the following fields set up in my sql tableIdNamePic emailand 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? Link to comment https://forums.phpfreaks.com/topic/287793-storing-array-data-into-mysql-table-how-help/ Share on other sites More sharing options...
Psycho Posted April 15, 2014 Share Posted April 15, 2014 You shouldn't. You should have a unique field for each piece of data. So, if you want to store the values for height, width, url & is_silhouette then you should create unique fields for each of them. Link to comment https://forums.phpfreaks.com/topic/287793-storing-array-data-into-mysql-table-how-help/#findComment-1476255 Share on other sites More sharing options...
Mancent Posted April 15, 2014 Author Share Posted April 15, 2014 Ok thank you. So how do I convert a array into fields in php example: Im going to search for it on the web. but any example would be awesome. Link to comment https://forums.phpfreaks.com/topic/287793-storing-array-data-into-mysql-table-how-help/#findComment-1476257 Share on other sites More sharing options...
Psycho Posted April 15, 2014 Share Posted April 15, 2014 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 https://forums.phpfreaks.com/topic/287793-storing-array-data-into-mysql-table-how-help/#findComment-1476262 Share on other sites More sharing options...
Mancent Posted April 15, 2014 Author Share Posted April 15, 2014 Really that's all.. So you can also just echo $array['id'] or any of the other fields in the array That's cool if that's true. Link to comment https://forums.phpfreaks.com/topic/287793-storing-array-data-into-mysql-table-how-help/#findComment-1476265 Share on other sites More sharing options...
Mancent Posted April 15, 2014 Author Share Posted April 15, 2014 Thank you man you just made my day al lot simpler. Link to comment https://forums.phpfreaks.com/topic/287793-storing-array-data-into-mysql-table-how-help/#findComment-1476273 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.