for($i=0;$cast_row = mysql_fetch_array($res);$i++)
{
$cast['id'][] = $cast_row['user_id'];
$cast['role'][] = $cast_row['role'];
$cast['role_name'][] = $cast_row['role_name'];
$cast['is_approved'][] = $cast_row['is_approved'];
$cast['movie_id'][] = $cast_row['movie_id'];
}
for($i=0;$i<count($cast['id']);$i++) //LINE 31
{
$output .= "<tr>";
$mname = getMovieNameById($m_id);
$output .= "<td><a href='single.php?id=$m_id'>$mname</a></td>";
$aname = getArtistNameById($cast['id'][$i]);
$output .= "<td><a href=project.php?id={$cast['id'][$i]}>$aname</a></td>";
}
此代码在Web服务器中正常工作,但在localhost上执行时会抛出错误(通知)
注意:未定义的索引:第31行的C:\ wamp \ www \ Tinyflick \ managemovie.php中的id
可能是什么问题?其余的代码似乎工作得很好
答案 0 :(得分:1)
这是一个愚蠢的错误.. 它解决了。感谢nico的评论
localhost中的错误报告级别与服务器上的错误报告级别不同。 改变这将成功。 以下代码将显示所有错误和警告
error_reporting(E_ALL)
通常在生产服务器上禁用警告。有关详细信息,请参阅documentation of the said function
答案 1 :(得分:0)
我猜mysql结果只是空的! :) 尝试转储你回来的行的内容。
不过,你可以通过这样的方式改进你的代码:while($row = mysql_fetch_array($res)) { // iterates as long there is content
//do something with the $row... like your second for block! ;)
}
答案 2 :(得分:0)
事实证明$cast array
为空,因为您没有正确地从数据库中获取数据。
如果您的服务器中的错误报告已关闭,那么您将看不到任何错误。
而不是for循环使用while循环来迭代从数据库中获取的数据。
$cast = array();
while($row = mysql_fetch_array($res)) {
$cast['id'][] = $row['user_id'];
$cast['role'][] = $row['role'];
$cast['role_name'][] = $row['role_name'];
$cast['is_approved'][] = $row['is_approved'];
$cast['movie_id'][] = $row['movie_id'];
}
然后你可以运行for循环。
答案 3 :(得分:0)
我想如果你想要抑制那些通知,请在循环之前添加以下行:
$cast = array('id'=>array(), 'role'=>array(), 'role_name'=>array(), 'is_approved'=>array(), 'movie_id'=>array() );
初始化变量。