Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to store particular array element of multi dimensional array in MySQL database.

8 views
Skip to first unread message

Anupam Jamatia

unread,
Feb 10, 2016, 3:48:57 AM2/10/16
to
I would like to know how to store the "message" in MySQL database from the pull of Facebook user timeline. The data are given below.

Array ( [0] => Array ( [story] => Arnab shared The Frustrated Engineer's video.
[created_time] => DateTime Object ( [date] => 2016-02-08 01:18:59.000000 [timezone_type] => 1 [timezone] => +00:00 ) [id] => 10154521329397892_10154534663442892 )
[1] => Array ( [message] => In leisure time [story] => Arnab with Nikhil Debbarma and Kunal Chakma.
[created_time] => DateTime Object ( [date] => 2016-01-21 13:21:07.000000 [timezone_type] => 1 [timezone] => +00:00 )[id] => 10154521329397892_10154491625882892 )
[2] => Array ( [story] => Arnab shared BVC Network's video.
[created_time] => DateTime Object ( [date] => 2016-01-20 03:53:36.000000 [timezone_type] => 1 [timezone] => +00:00 )[id] => 10154521329397892_10154488463402892 )
[3] => Array ( [story] => Arnab shared a link.
[created_time] => DateTime Object ( [date] => 2016-01-19 05:31:50.000000 [timezone_type] => 1 [timezone] => +00:00 )[id] => 10154521329397892_10154486306352892 )
[4] => Array ( [message] => Today is 19th of January #KokborokDay pls hashtag and let everyone in the region and India know about us..irrespective of our affiliations...pls share Joto tiprasa Dopha ni takhuk tai bukhu songno Tini #kokborok # saal ni Khapang ni Hamjakma tai Chibai Yafaro #Kokborok Hambai
[created_time] => DateTime Object ( [date] => 2016-01-19 02:29:27.000000 [timezone_type] => 1 [timezone] => +00:00 )[id] => 10154521329397892_10154486019362892 )
[5] => Array ( [story] => Arnab shared 24 Ghanta's post.
[created_time] => DateTime Object ( [date] => 2016-01-18 06:44:24.000000 [timezone_type] => 1 [timezone] => +00:00 )
[id] => 10154521329397892_10154484071437892 )
[id] => 10154521329397892_10154460030042892 )
[6] => Array ( [message] => Earthquake!!!
[created_time] => DateTime Object ( [date] => 2016-01-03 23:08:33.000000 [timezone_type] => 1 [timezone] => +00:00 )
[id] => 10154521329397892_10154449834967892 )
[7] => Array ( [message] => Pranam, Jai Hind. 🙏
[story] => Arnab shared The Logical Indian's post.
[created_time] => DateTime Object ( [date] => 2016-01-03 13:17:40.000000 [timezone_type] => 1 [timezone] => +00:00 )
[id] => 10154521329397892_10154448752967892 )
[8] => Array ( [message] => To all my dear friends, colleagues, relatives.
[created_time] => DateTime Object ( [date] => 2015-12-31 17:46:02.000000 [timezone_type] => 1 [timezone] => +00:00 ) [id] => 10154521329397892_10154441604347892 )
[9] => Array ( [story] => Arnab shared a link.
[created_time] => DateTime Object ( [date] => 2015-12-31 09:11:41.000000 [timezone_type] => 1 [timezone] => +00:00 ) [id] => 10154521329397892_10154440618227892 )
[10] => Array ( [message] => R. I. P.
[created_time] => DateTime Object ( [date] => 2015-12-31 02:41:27.000000 [timezone_type] => 1 [timezone] => +00:00 ) [id] => 10154521329397892_10154440076302892 )
)



Suppose, if the data are stored in an array like $total_posts = array(); it is possible to print the "message" on the screen.

I have used the following code


$total_posts = array();
$posts_response = $posts_request->getGraphEdge();
if($fb->next($posts_response)) {
$response_array = $posts_response->asArray();
$total_posts = array_merge($total_posts, $response_array);
while ($posts_response = $fb->next($posts_response)) {
$response_array = $posts_response->asArray();
$total_posts = array_merge($total_posts, $response_array);
}
//print_r($total_posts);

foreach ($total_posts as $key ) {
echo $key['message'].'<br>';
}


} else {
$posts_response = $posts_request->getGraphEdge()->asArray();
print_r($posts_response);
}


$total_message = $total_posts['message'];


$sql = "INSERT INTO users1 (name, token, message) VALUES ('$name', '$accessToken', '$total_message')";
if ($db->query($sql) === TRUE) {
echo "New record created successfully !!";
} else {
echo "Error: " . $sql . "<br>" . $db->error;
}
$db->close();
But I am not able to store the message in the database.


Is there anyone who can help on this issue please. Regards

0 new messages