Error_log
[2013年8月16日20:41:33 America / Sao_Paulo] PHP警告:在第9行的/home/public_html/acp/includes/templates/character.php中为foreach()提供的参数无效
My Character.php
<?php
if (!isset($included) || !$included) exit();
$buttons = "";
$empty = true;
$characters = $_handlerGameServer->fetch($_queryGame['characters'],array($session->get("account")));
foreach ($characters as $character) {
$buttons .= "<button class='buttonProcess' name='select_character' title='character_id' value='".$character[0]."'>".$character[1]."</button>\n";
$empty = false;
}
if (!$empty)
$_templatePage->replace("buttons",$buttons);
else
$_templatePage->replace("buttons",$_lang['error']['noCharacters']."<br /><a href='?page=select_server' class='linkProcess' name='unset_server'>".$_lang['character']['changeServer']."</a> | <a href='?page=account' class='linkProcess' name='logout'>".$_lang['character']['logout']."</a> ");
?>
答案 0 :(得分:0)
如果你的函数返回false或为空,你可以这样做:
if($characters = $_handlerGameServer->fetch($_queryGame['characters'],array($session->get("account")))) {
foreach ($characters as $character) {
$buttons .= "<button class='buttonProcess' name='select_character' title='character_id' value='".$character[0]."'>".$character[1]."</button>\n";
}
$_templatePage->replace("buttons",$buttons);
} else {
$_templatePage->replace("buttons",$_lang['error']['noCharacters']."<br /><a href='?page=select_server' class='linkProcess' name='unset_server'>".$_lang['character']['changeServer']."</a> | <a href='?page=account' class='linkProcess' name='logout'>".$_lang['character']['logout']."</a> ");
}