我的foreach循環不適用於mysql中的update語句。不知道我做錯了什麼。這裏是我的PHP片段。PHP和MYSQL:更新不適用於Foreach循環
foreach ($request['playlist_information'] as $playlist) {
$playlistResult = "UPDATE video_playlists SET channel_id='".$playlist['channel_id']."', playlist_id='".$playlist['id']."', playlist_title='".$playlist['title']."', playlist_status='".$playlist['status']."', playlist_description='".$playlist['description']."', playlist_created='".$playlist['date_created']."'";
$mysqli->query($playlistResult);
var_dump($playlist['title']);
}
和我的要求,從我的JavaScript來是這樣的:
var param = {
"channel_id": channelId,
"video_id": videoId,
"views": $scope.stats[0]['views'],
"likes": $scope.stats[0]['likes'],
"dislikes": $scope.stats[0]['dislikes'],
"favorites": $scope.stats[0]['favorites'],
"comments": $scope.stats[0]['comments'],
"duration": $scope.stats[0]['duration'],
"dimension": $scope.stats[0]['dimension'],
"definition": $scope.stats[0]['definition'],
"caption": $scope.stats[0]['caption'],
"licensed_content": licensedContent,
"upload_status": $scope.stats[0]['uploadStatus'],
"privacy_status": $scope.stats[0]['privacyStatus'],
"license": $scope.stats[0]['license'],
"embeddable": embeddable,
"public_stats_viewable": publicStatsViewable,
"video_title": $scope.meta[0]['title'],
"video_status": $scope.stats[0]['privacyStatus'],
"video_description": $scope.meta[0]['description'],
"video_tags": $scope.meta[0]['tags'],
"playlist_information": {}
}
for (var i = 0; i < $scope.playlists.length; i++) {
param["playlist_information"][i] = {
"channel_id": channelId,
"id": $scope.playlists[i]['id'],
"title": $scope.playlists[i]['title'],
"description": $scope.playlists[i]['description'],
"status": $scope.playlists[i]['status'],
"date_created": $scope.playlists[i]['datePublished']
}
};
INSERT工作正常,我可以不用在PHP的一部分foreach循環更新的罰款。我似乎無法找出問題所在。任何幫助表示讚賞。謝謝!
'的print_r($ _ POST)'在php文件中看到柱結構是什麼樣子.. – superphonic
什麼是錯誤,使用一些調試,讓我們知道確切的問題 – Noor
print_r($ _ POST)顯示和空陣列。順便說一句我正在使用angularjs和創建一個YouTube的API應用程序。 – Growlithe