PHP未定义偏移量

PHP未定义偏移量,php,undefined,offset,Php,Undefined,Offset,我正在制作一个照片库,每一张照片我都能看到照片上有多少评论。我的代码工作正常,只是如果有0条注释,它将给出“未定义的偏移量错误:2” '未定义的偏移错误:3' '未定义的偏移错误:4' '未定义的偏移错误:5' 等等 这是检查有多少注释的代码: (反应=评论) 这是显示图片和评论数量的代码: for($i=$begin; $i < $eind; $i++){ $thumb = str_replace($path2, $thumbPath, $fotoArray[$i]);

我正在制作一个照片库,每一张照片我都能看到照片上有多少评论。我的代码工作正常,只是如果有0条注释,它将给出“未定义的偏移量错误:2”
'未定义的偏移错误:3'
'未定义的偏移错误:4'
'未定义的偏移错误:5'
等等

这是检查有多少注释的代码: (反应=评论)

这是显示图片和评论数量的代码:

for($i=$begin; $i < $eind; $i++){ 


$thumb = str_replace($path2, $thumbPath, $fotoArray[$i]); 

   echo "<td align='center'><a href='" . $_SERVER['PHP_SELF'] . "?page=album&boek=" .     $originalPath . "&fotoID=" . $i . "'><img border='0' src='" . $thumb . "' height='100'><br>"; 
echo "<small>reacties ("; 
if($reacties[$i]==0){ 
    echo "0"; 
    } // end if 
else { 
echo $reacties[$i]; 
    } // end else     
echo ")</small>"; 
echo "</a></td>"; 
    $fotonr++; 
    if($fotonr == ($clm + 1)){ 
    echo "</tr>\n<tr>"; 
     $fotonr = 1; 
} // end if 
for($i=$begin;$i<$eind;$i++){
$thumb=str_replace($path2,$thumbPath,$fotoArray[$i]);
回声“;
$fotonr++;
如果($fotonr==($clm+1)){
回音“\n”;
$fotonr=1;
}//如果结束,则结束

如果有人知道我做错了什么和/或知道如何解决这个问题,那就太好了!

您可以在查询中嵌入计数器:

选择foto,将(*)计算为fotosreacties中的counter_comments,其中boek='“$\u GET['boek']”
。在结果中,您可以使用
$r['counter_comments']
并检查其值是否为0或更多

关于您的代码:

  • 停止在新应用程序中使用
    MySQL
    -函数,因为它们很快就会被弃用。请改用MySQLi或PDO
  • 永远不要信任用户输入,比如
    $\u GET
    ,至少要通过(例如)
    mysql\u real\u escape\u string()
    对其进行清理

Thnx获取答案和其他提示,但我仍然无法让它工作。您可以在代码中向我展示您的解决方案吗?
for($i=$begin; $i < $eind; $i++){ 


$thumb = str_replace($path2, $thumbPath, $fotoArray[$i]); 

   echo "<td align='center'><a href='" . $_SERVER['PHP_SELF'] . "?page=album&boek=" .     $originalPath . "&fotoID=" . $i . "'><img border='0' src='" . $thumb . "' height='100'><br>"; 
echo "<small>reacties ("; 
if($reacties[$i]==0){ 
    echo "0"; 
    } // end if 
else { 
echo $reacties[$i]; 
    } // end else     
echo ")</small>"; 
echo "</a></td>"; 
    $fotonr++; 
    if($fotonr == ($clm + 1)){ 
    echo "</tr>\n<tr>"; 
     $fotonr = 1; 
} // end if