jch02140 Posted August 11, 2011 Share Posted August 11, 2011 I am currently testing facebook PHP API but unsure how to store the values to MySQL.I am able to output the array data of my facebook info as follows with the code using the facebook php SDK: foreach ($user_profile AS $key =>$value){ echo "\$key = " . $key . "<br />"; echo "\$value = " . $value . "<br />";} $key = id$value = 123456789$key = name$value = First Last$key = first_name$value = First$key = last_name$value = Last$key = username$value = abcd$key = hometown$value = Array$key = location$value = Array...How do I insert the data into mysql if let say my table name is user_info and have the following fields: facebook_id, first_name, last_name, username, hometownIs there a method to get the values from sub-arrays as well? Link to comment Share on other sites More sharing options...
thescientist Posted August 11, 2011 Share Posted August 11, 2011 you would need to use a foreach loop to loop through all the sub arrays. Once you have access to all the variables you need, just put it into an INSERT query. It might be easier to assign each key/value to a variable first. Link to comment Share on other sites More sharing options...
jch02140 Posted August 14, 2011 Author Share Posted August 14, 2011 I was thinking something like this? foreach ($user_profile AS $key =>$value){ if ($value == "Array") { foreach ($user_profile AS $key =>$value) { echo "\$key = " . $key . "<br />"; echo "\$value = " . $value . "<br />"; } } else { echo "\$key = " . $key . "<br />"; echo "\$value = " . $value . "<br />"; }} Also, I think it might also work using switch statements.... Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.