1

PHP コードの後に​​ HTML の下半分が表示されないページがあります。表示させる唯一の方法は、 WHILEループの最後にRETURNを配置することでした。これにより、ループも終了しました。おそらく単純なものであり、それが何であるかを知る必要があることはわかっています。よろしくお願いします。

HTML:

<table border='0'>
 <thead>
     <tr>
        <th scope="cols">Select</th>
        <th scope="cols">Name</th>
        <th scope="cols">Units</th>
        <th scope="cols">Amounts</th>
        <th scope="cols">Calories</th>
        <th scope="cols">Sugars</th>
   </tr>
 </thead>
 <tbody>
    <?php 
         //Establishs the DB connection
         $sql = new Mysql();

         //Queries the Foods
         $sql->food();
      ?> <!--NOTHING SHOWS FROM HERE DOWN-->
  </tbody>    
</table>
<h2>Training Plan</h2>
<table id="dairy">
 <thead>
     <tr>
        <th scope="cols">Select</th>
        <th scope="cols">Name</th>
        <th scope="cols">Units</th>
        <th scope="cols">Amounts</th>
        <th scope="cols">Calories</th>
        <th scope="cols">Sugars</th>
     </tr>
     ...more HTML....

PHP 関数:

function food() {
   //Query's the DB
   $result = $this->conn->query("SELECT * FROM ingredient")  or die(mysql_error());

   //Display's all of the Contents in the DB
   while ($row = $result->fetch_assoc() or die(mysql_error()))
   {
       echo'<tr class="normal" id="row'.$row['id'].'" onclick="onRow(this.id);">'."\n\t\t\t\t\t\t\t".'<td><input type="checkbox" value="'.$row['id'].'" id="checkbox" /></td>'."\n\t\t\t\t\t\t\t";
       echo'<td>'.$row['Name'].'</td>'."\n\t\t\t\t\t\t\t";
       echo'<td>'.$row['Units'].'</td>'."\n\t\t\t\t\t\t\t";
       echo'<td>'.$row['Amount'].'</td>'."\n\t\t\t\t\t\t\t";
       echo'<td>'.$row['Calories'].'</td>'."\n\t\t\t\t\t\t\t";
       echo'<td>'.$row['Sugar'].'</td>'."\n\t\t\t\t\t\t";
       echo'</tr>'."\n\t\t\t\t\t\t";
   }
}
4

2 に答える 2

1
while ($row = $result->fetch_assoc() or die(mysql_error()))

問題はこの行に$result->fetch_assoc()あります。行がなくなったときに false を返すと (そうなると思います)、スクリプトは停止します。型の部分を残す

while ($row = $result->fetch_assoc())
于 2012-08-08T01:03:39.333 に答える
0

エラーが発生したため、表示されません。food は $sql クラスのメンバーですか?

于 2012-08-08T00:57:06.120 に答える