1

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);">'."\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";
   }
}
3
  • What shows up in your error log? Commented Aug 8, 2012 at 0:57
  • 1
    Also, wow, you really need to learn about printf(). And apostrophes. Commented Aug 8, 2012 at 0:58
  • 1
    mysql_* functions are deprecated, try to use mysqli_* or PDO Commented Aug 8, 2012 at 0:58

2 Answers 2

1
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())
Sign up to request clarification or add additional context in comments.

1 Comment

Yep! That was it. I appreciate the inputs. I knew it would be something simple but it always seems that error finding is hard when you staring at it for a while. Thanks again.
0

It's not showing because you have an error. Is food a member of the $sql class?

2 Comments

I dont know why you got a -ve for this. I was thinking the same answer you gave, even though I agree that maybe adding a bit more to the answer would help. But I do hate it when people get trigger-happy with the ratings and leave without explaining their rationale!
Hey-ho.I should learn to put things in comments.I shouldn't have posted as an answer,with a question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.