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] => 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? Quote 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. Quote 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. Quote 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...
Solution Psycho Posted April 15, 2014 Solution 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, Quote 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. Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.