2013-02-09 106 views
-6
<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 
    <title></title> 
</head> 
<body> 
    <?php 
    $table = array ("1", "2", "3", "4", "5"); 
    $count = count($table); 
    echo "<table border='1'>"; 
    $rows = 5; 
    for($i=0; $i <= $count; $i = $i + $rows) 
    { 
     echo "<tr>"; 
     for($z = 0; $z < $rows; $z++) 
     { 
      if ($table[$i + $z] !=0) 
       echo "<td>This is row {$table[$i + $z]}</td></tr>"; 
      else 
       echo "<td>&nbsp;</td></tr>"; 
     } 
    } 
    echo "</table>" 
    ?> 
</body> 
</html> 

這是我一直在努力工作一段時間的代碼,而其他一切正常的情況下,運行時會出現問題。它顯示了我所想要的桌子上,但在桌子底下它的帖子:未定義偏移量:5

Notice: Undefined offset: 5 in [file location] on line 22 
Notice: Undefined offset: 6 in [file location] on line 22 
Notice: Undefined offset: 7 in [file location] on line 22 
Notice: Undefined offset: 8 in [file location] on line 22 
Notice: Undefined offset: 9 in [file location] on line 22 

我知道問題是圍繞價值,但不管如何我把它變成,它要麼刷新「= 0!」全部努力或重複相同的消息。

回答

0
  1. 您在以下聲明中錯過了;

    echo "</table>" 
    
  2. 你迭代在5 $i + $rows步驟,您$table可以去最多$table[4]
  3. 錯誤/通知是因爲相同。
0
<?php 
if(isset($_POST['submit'])){ 
    $the_file = file($_FILES['the_file']['tmp_name']); 
    for($i = 0; $i < count($myfile); ++$i){ 
     echo $myfile[$i] . "<br/>"; 
     echo "Line " . ($i + 1) . " is " .strlen($myfile[$i]) . " characters long<br/>"; 
    } 
} 
?> 


<form method="post" action="myphp.php" enctype='multipart/form-data' > 
    <input type="file" name="the_file" value="Yes"/> 
    <input type="submit" name="submit" value="No"/> 
</form> 
+2

如果你提供一些你在做什麼以及它爲什麼工作的解釋,答案會更有幫助。 – 2013-12-10 16:17:55

1

我已經得到了同樣的錯誤代碼,但我設法找到這一問題。你得到的錯誤信息與數組有關。看來你正在引用一個未定義的數組[鍵]: for($i=0; $i <= $count; $i = $i + $rows)$i = $i + $rows是罪魁禍首。例如:$i = 0$rows=5; so 0 + 5 = 5 so array [5]並且這個不存在於數組中。它只能用$table數組到4。 希望這可以幫助你和/或其他人。