警告foreach的无效参数()
问题描述:
好的,我最近购买了一个名为WPArcade的wordpress插件,但是,我一直有一些问题。特别是我无法让自己的游戏像他们想象的那样喂食。当我尝试从比如说Kongregate那里提供游戏时,它说找到0个游戏,但也给我这个错误:警告foreach的无效参数()
警告:为C:\ Program Files(x86)\ Ampps \ www \ wp \ wp-content \ plugins \ wparcade-plugin \ feeds \ kongregate \ kongregate.php on line 113
我正在测试本地服务器上的站点,这就是它在C驱动器中的原因。
Kongregates饲料:http://www.kongregate.com/games_for_your_site.xml
这与每个出版社中发生的插件,除了一个不把我的警告。
线113至155:Kongregate的
$xml = simplexml_load_string($get_kongregate_feed);
foreach($xml->game as $game) {
$id = intval($game->id);
$name = mysql_real_escape_string($game->title);
$check_id = $wpdb->get_var("SELECT id FROM ".$wpdb->prefix."wparcade_kongregate_games WHERE id = '$id'");
$count = mysql_result(mysql_query("SELECT COUNT(*) as newgames FROM ".$wpdb->prefix."wparcade_kongregate_games WHERE id = '$check_id'"),0);
if($count !== '1') {
$name = mysql_real_escape_string($game->title);
$slug = mysql_real_escape_string($game->title);
$slug = wparcade_stringforslug($slug);
$category = mysql_real_escape_string($game->category);
$category = wparcade_strstr_before($category, " & ");
if(!$category) $category = mysql_real_escape_string($game->category);
$categories = mysql_real_escape_string($game->category);
$categories = str_replace(' & ', ', ', $categories);
if(!$categories) $categories = mysql_real_escape_string($game->category);
$description = mysql_real_escape_string($game->description);
$instructions = mysql_real_escape_string($game->instructions);
$thumbnail_url = mysql_real_escape_string($game->thumbnail);
$swf_url = mysql_real_escape_string($game->flash_file);
$width = $game->width;
$height = $game->height;
$tags = strtolower($categories);
$author = mysql_real_escape_string($game->developer_name);
$wparcade_kongregate_feed_game_status = $options['kongregate_feed_game_status'];
$status = $wparcade_kongregate_feed_game_status;
$feedsinglecat_id = $options['kongregate_feed_single_cat'];
$feedcategory = get_cat_name($feedsinglecat_id);
if($feedsinglecat_id !== 'none') {
$categories = $feedcategory;
$category = $feedcategory;
}
$sql = "INSERT INTO ".$wpdb->prefix."wparcade_kongregate_games (id, name, slug, description, thumbnail_url, swf_url, width, height, author, categories, category, tags, instructions, status) VALUES ('$id', '$name', '$slug', '$description', '$thumbnail_url', '$swf_url', '$width', '$height', '$author', '$categories', '$category', '$tags', '$instructions', '$status')";
$list .= '<li class="wparcade_new_games""><strong>'.$name.'</strong></li>';
$wpdb->query($sql);
$inserted++;
} else {
$list .= '<li class="wparcade_old_games"><strong>'.$name.'</strong></li>';
}
}
以防万一,这是唯一的饲料所使用的代码:
$xml = simplexml_load_string($get_scirra_feed);
foreach($xml->game as $game) {
$id = intval($game->gameid);
$name = mysql_real_escape_string($game->name);
$count = mysql_result(mysql_query("SELECT COUNT(*) as newgames FROM ".$wpdb->prefix."wparcade_scirra_games WHERE id = '$id'"),0);
$category = mysql_real_escape_string($game->category);
$slug = mysql_real_escape_string($game->name);
$slug = wparcade_stringforslug($slug);
$check_for = $wpdb->get_var("SELECT name FROM ".$wpdb->prefix."wparcade_scirra_games WHERE slug = '$slug'");
if($count !== '1' && $category !== 'Example' && !$check_for) {
$name = mysql_real_escape_string($game->name);
$slug = mysql_real_escape_string($game->name);
$slug = wparcade_stringforslug($slug);
$category = mysql_real_escape_string($game->category);
$category = str_replace('Shooter', 'Shooting', $category);
$category = str_replace('Defence', 'Defense', $category);
$category = str_replace('Puzzle', 'Puzzles', $category);
$category = str_replace('Rotary', 'Arcade, Rotary', $category);
$categories = $category;
$description = strip_tags(mysql_real_escape_string($game->description));
$instructions = strip_tags(mysql_real_escape_string($game->instructions));
$thumbnail_url = $game->images->small;
$thumbnail_large_url = $game->images->medium;
$screen1_url = $game->images->big;
$embed_url = mysql_real_escape_string($game->embedurl);
$embed_url = str_replace('http://', '//', $embed_url);
$embed_url = str_replace('//', 'http://', $embed_url);
$width = $game->width;
$height = $game->height;
$tags = strtolower($categories);
$author = mysql_real_escape_string($game->author->username);
$wparcade_scirra_feed_game_status = $options['scirra_feed_game_status'];
$status = $wparcade_scirra_feed_game_status;
$feedsinglecat_id = $options['scirra_feed_single_cat'];
$feedcategory = get_cat_name($feedsinglecat_id);
if($feedsinglecat_id !== 'none') {
$categories = $feedcategory;
$category = $feedcategory;
}
$sql = "INSERT INTO ".$wpdb->prefix."wparcade_scirra_games (id, name, slug, description, thumbnail_url, thumbnail_large_url, screen1_url, embed_url, width, height, author, categories, category, tags, instructions, status) VALUES ('$id', '$name', '$slug', '$description','$thumbnail_url', '$thumbnail_large_url', '$screen1_url', '$embed_url', '$width', '$height', '$author', '$categories', '$category', '$tags', '$instructions', '$status')";
$list .= '<li class="wparcade_new_games""><strong>'.$name.'</strong></li>';
$wpdb->query($sql);
$inserted++;
} else {
$list .= '<li class="wparcade_old_games"><strong>'.$name.'</strong></li>';
}
}
感谢您提前任何帮助。
P.S.我问了插件的支持网站,但已经差不多一个星期没有答案。
答
这里的问题是Kongregate $ xml->游戏不是一个可迭代的对象(如数组)。调试简单的方法是在线路113尝试插入类似:
print_r($xml->game);
//or
print_r($xml);
获取数据的可视性是什么,是不工作可能会帮助你更好地理解为什么这是行不通的。祝你好运!
不知道如何查看,但。插入到程序中不会改变任何东西,当我运行饲料。现在我只在下一行发生错误,没有打印信息。 – saltin3s 2015-04-04 22:54:38
只需通过打印出行来保持向后工作,直到找到导致问题的行。如果其余部分没有响应,请尝试打印$ get_kongregate_feed,以确保您传递正确的数据。您需要更好地了解实际值。如果你拉这个,继续并发布你想加载的网址 – DaOgre 2015-04-04 23:01:24
我想你误解了我的问题。我不知道如何实际打印行以找到它们的值,因为当我更改代码时,它不会显示打印的文本,当我运行该插件的特定部分时。 – saltin3s 2015-04-04 23:40:22