我有两个id
。一个是id
Facebook 的comment
,第二个是 Facebook 朋友的 id。我想将这些存储在两个数据库中。id
在表Post
中评论friend id
。User
我面临的问题是“id”值被覆盖了。
检索数据:
{
"data": [
{
"id": "aaaaaaaaaaaaaaaa",
"from": {
"name": "xxxx xxxx",
"id": "111111111"
},
"message": "fetch this comment :P",
"can_remove": true,
"created_time": "2013-06-05T09:00:00+0000",
"like_count": 0,
"user_likes": false
},
{
"id": "aaaaaaaaaaaaaaaa",
"from": {
"name": "xxxxxxxxx",
"id": "111111111"
},
"message": "Fetching comments.",
"can_remove": true,
"created_time": "2013-06-05T17:22:34+0000",
"like_count": 0,
"user_likes": false
},
{
"id": "aaaaaaaaaaaaaaaa",
"from": {
"name": "xxxxxxxxx",
"id": "11111111111"
},
"message": "?",
"can_remove": true,
"created_time": "2013-06-05T17:27:55+0000",
"like_count": 0,
"user_likes": false
},
代码 :
foreach($jsonIterator as $key => $val) {
echo "$key: => $val";
$post_obj_insert->user_id = $question->user_id;
if($key=='from'){
$user_obj->where('FacebookId', $val)->get();
if($user_obj->FacebookId=''){
if($key=='name'){
$user_obj->name = $val;
$flag_usr = $flag_usr + 1;
}
if($key=='id'){
$user_obj->id = $val;
$flag_usr = $flag_usr + 1;
}
$user_obj->FacebookId = $val;
$flag_usr = $flag_usr + 1;
}
if($flag_usr==2){
$user_obj->isRegistered=0;
$user_obj->save();
$user_obj = new user();
}
}
else if($key=='message'){
$post_obj_insert->post_text = $val;
$flag=$flag+1;
}
else if($key=='like_count'){
$post_obj_insert->count = $val;
$flag=$flag+1;
}
else if($key=='id'){
$post_obj_insert->facebook_post_id = $val;
$flag=$flag+1;
}
if($flag==3){
$post_obj_insert->save();
$flag=0;
$post_obj_insert = new Post();
}
}