2014-01-25 110 views
-1

我正在制作照片库,并且每张照片都可以看到该照片上有多少评论。我已经工作像它的代码应该只是如果已有0条评论这将给“未定义偏移误差:2”
“未定义失调误差:3”
“未定义失调误差:4”
“未定义偏置误差:5'
PHP未定义偏移

这是检查有多少评论有代码: (reacties =评论)

// check how many comments every photo has. 
$reacties; 
$query = "select foto from fotosreacties where boek = '" . $_GET['boek'] . "'"; 
if($result = mysql_query($query)){ 
while ($r = mysql_fetch_array($result)){ 
    while ($foto = current($fotoArray)) { 
      if ($foto==$r["foto"]){ 
       $key = key($fotoArray); 
       } // end if 
      next($fotoArray); 
     } // end while 
    if(!isset($reacties[$key])){ 
     $reacties[$key] = 1; 
     } // end if  
    else { 
     $reacties[$key]++; 
     } // end else  
     reset($fotoArray); 

    } // end while 
} // end if  

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

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 

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

回答

0

您可以嵌入在查询柜台:

select foto, count(*) AS counter_comments from fotosreacties where boek = '" . $_GET['boek'] . "'。在结果中,您可以使用$r['counter_comments']并检查其是否为0或更多。

关于你的代码:

  • 使用MySQL -functions在新的应用程序,因为他们不久将被取消停止。改用MySQLi或PDO!
  • 永远不要相信像$_GET这样的用户输入,您至少应该通过(例如)mysql_real_escape_string()来清除它。
+0

Thnx的答案和其他技巧,但我仍然无法得到它的工作。你能否在代码中向我展示你的解决方案? – Daanvn