I have an array followers_array and inside that I have array followers. Now I want to insert all the data in database. I have tried this but this insert only three data and not all I want to insert data of an array which contain another array.
example
Array
(
[0] => Array
(
[id] => 1766191289
[username] => club_prichesok
[profie_pic_url] => http://scontent-sin6-1.cdninstagram.com/t51.2885-19/s150x150/13652273_1748726562036923_750729706_a.jpg
)
[1] => Array
(
[id] => 1825482289
[username] => recepturo
[profie_pic_url] => http://scontent-sin6-1.cdninstagram.com/t51.2885-19/13269510_1062313797193421_2145524856_a.jpg
)
[2] => Array
(
[id] => 1558269170
[username] => bossbabesbrand
[profie_pic_url] => http://scontent-sin6-1.cdninstagram.com/t51.2885-19/s150x150/13652188_776051655868683_440592047_a.jpg
)
[3] => Array
(
[id] => 3150718948
[username] => aiyubpixster1
[profie_pic_url] => http://scontent-sin6-1.cdninstagram.com/t51.2885-19/s150x150/14597497_1333447786679600_2495297650182586368_a.jpg
)
[4] => Array
(
[id] => 3126365193
[username] => aiyubmunshi22
[profie_pic_url] => http://scontent-sin6-1.cdninstagram.com/t51.2885-19/s150x150/12960010_1525961487711830_121043771_a.jpg
)
[5] => Array
(
[id] => 786675309
[username] => a_trvn
[profie_pic_url] => http://scontent-sin6-1.cdninstagram.com/t51.2885-19/s150x150/14478472_200908700343641_544747813301387264_a.jpg
)
[6] => Array
(
[id] => 3920937922
[username] => campins09
[profie_pic_url] => http://scontent-sin6-1.cdninstagram.com/t51.2885-19/s150x150/14515676_1750967491822509_1220506517271216128_a.jpg
)
[7] => Array
(
[id] => 3101694007
[username] => apriyapari
[profie_pic_url] => http://scontent-sin6-1.cdninstagram.com/t51.2885-19/s150x150/12907442_1754066311508992_471114618_a.jpg
)
[8] => Array
(
[id] => 3522063531
[username] => soccergirrl.x
[profie_pic_url] => http://scontent-sin6-1.cdninstagram.com/t51.2885-19/s150x150/14566773_1820095541541963_7245353788171616256_n.jpg
)
[9] => Array
(
[id] => 4307621933
[username] => carmii_licious
[profie_pic_url] => http://scontent-sin6-1.cdninstagram.com/t51.2885-19/s150x150/15624190_382611378742665_5984516355464888320_a.jpg
)
[10] => Array
(
[id] => 4120637171
[username] => _cek.newphoto.or.unfollow_
[profie_pic_url] => http://scontent-sin6-1.cdninstagram.com/t51.2885-19/s150x150/15306790_705623506273370_4297264141430685696_a.jpg
)
[11] => Array
(
[id] => 3019429401
[username] => gungaoto
[profie_pic_url] => http://scontent-sin6-1.cdninstagram.com/t51.2885-19/s150x150/14624240_214178872360167_5880385332934868992_a.jpg
)
[12] => Array
(
[id] => 4157340771
[username] => hairstyle_makeup_style
[profie_pic_url] => http://scontent-sin6-1.cdninstagram.com/t51.2885-19/s150x150/15306541_1806174429600270_600008151021912064_a.jpg
)
[13] => Array
(
[id] => 3514079761
[username] => jemxma_esrn
[profie_pic_url] => http://scontent-sin6-1.cdninstagram.com/t51.2885-19/s150x150/14606945_318707198522914_4406240531315687424_a.jpg
)
[14] => Array
(
[id] => 4374792130
[username] => liindsay20
[profie_pic_url] => http://scontent-sin6-1.cdninstagram.com/t51.2885-19/s150x150/15876231_1774071109522171_5041779443538853888_a.jpg
)
[15] => Array
(
[id] => 3669715747
[username] => subhanallahh__
[profie_pic_url] => http://scontent-sin6-1.cdninstagram.com/t51.2885-19/s150x150/15534754_192323887898801_4040343084729368576_a.jpg
)
[16] => Array
(
[id] => 3111272383
[username] => irshad.pixster
[profie_pic_url] => http://scontent-sin6-1.cdninstagram.com/t51.2885-19/11906329_960233084022564_1448528159_a.jpg
)
[17] => Array
(
[id] => 1114256851
[username] => pixsterstudio
[profie_pic_url] => http://scontent-sin6-1.cdninstagram.com/t51.2885-19/11335149_984470211587963_1696181727_a.jpg
)
[18] => Array
(
[id] => 4374336687
[username] => putrysyafinazsyuhizam
[profie_pic_url] => http://scontent-sin6-1.cdninstagram.com/t51.2885-19/s150x150/15875998_185924578548483_3898112154640842752_n.jpg
)
now my table in database contain three fields id username and profile_pic_url I want to insert these data in database.I tried but it saves only three data where as I have 25 data in array.
whole code Here is my full code. please tell me where am I going wrong.
<?php
error_reporting(0);
require('./vendor/autoload.php');
$con = mysql_connect('localhost','root','') or die('Cannot connect to the DB');
mysql_select_db('insta',$con);
$username = $_GET['user'];
$pass = $_GET['pass'];
if(!empty($pass) && !empty($username))
{
$i = new \InstagramAPI\Instagram(false);
$i->setUser($username, $pass);
if($i->settings->islogged() == false)
{
echo "You are not logged in.";
}
else
{
$a = $i->getUsernameId($username);
$helper = null;
$followers = [];
$followers_array = array();
do {
if (is_null($helper)) {
$helper = $i->getSelfUserFollowers();
} else {
$helper = $i->getSelfUserFollowers($helper->getNextMaxId());
}
$followers = array_merge($followers, $helper->getUsers());
} while (!is_null($helper->getNextMaxId()));
foreach ($followers as $follower) {
$username = $follower->getUsername();
$profie_pic_url = $follower->getProfilePicUrl();
$id = $follower->getPk();
$status = $i->userFriendship($id);
$query = mysql_query("INSERT INTO `followers` (username,profile_pic_url,follower_id)
VALUES ('".$username."','".$profie_pic_url."','".$id."')");
// if ($status->getFollowing() == false)
// {
array_push($followers_array,array('id' => $id,'username' => $username,'profie_pic_url' => $profie_pic_url));
// }
}
if($query){
echo "Data inserted </br>";
}
echo "<pre>";
print_r($followers_array);
}
}
else
{
echo"username is required";
}
?>