I have a page that will not show the bottom half of my HTML after my PHP Code. The only way I could get it to show was to place a RETURN at the end of the WHILE Loop, which also ended the loop. I know it is probably something simple and just need to find out what it is. Thanks in advance for your help.
The 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....
The PHP Function:
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);">'."
\t\t\t\t\t\t\t".'<td><input type="checkbox" value="'.$row['id'].'" id="checkbox" /></td>'."
\t\t\t\t\t\t\t";
echo'<td>'.$row['Name'].'</td>'."
\t\t\t\t\t\t\t";
echo'<td>'.$row['Units'].'</td>'."
\t\t\t\t\t\t\t";
echo'<td>'.$row['Amount'].'</td>'."
\t\t\t\t\t\t\t";
echo'<td>'.$row['Calories'].'</td>'."
\t\t\t\t\t\t\t";
echo'<td>'.$row['Sugar'].'</td>'."
\t\t\t\t\t\t";
echo'</tr>'."
\t\t\t\t\t\t";
}
}
while ($row = $result->fetch_assoc() or die(mysql_error()))
The problem is in this line, if $result->fetch_assoc()
returns falsy when there are no more rows(which I suspect it does) you script will be stopped. Leave out the die part
while ($row = $result->fetch_assoc())
It's not showing because you have an error. Is food a member of the $sql class?