我有一个页面在我的 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";
}
}