1

I received the following error message when I tried to show the content in my dashboard. How may I fix it?

the code is

       <?php foreach ($sections as $row) : ?>
            <tr>
                <td><?php echo $row['ht_id'] ?></td>
                <td><?php echo $row['Sections'] ?></td>
                <td><?php echo $row['ht_descr'] ?></td>
                <td>
                <a href="edit_section.php?section_id=<?php echo $row['ht_id'] ?>&operation=edit" class="btn btn-primary" style="margin-right: 8px;"><span class="glyphicon glyphicon-edit"></span>

                <a href=""  class="btn btn-danger delete_btn" data-toggle="modal" data-target="#confirm-delete-<?php echo $row['ht_id'] ?>" style="margin-right: 8px;"><span class="glyphicon glyphicon-trash"></span></td>
            </tr>
      <?php endforeach;?>

the ht_id and the ht_descr are good there is nothing wrong with it only the Sections row give me the error

Regolith
  • 2,944
  • 9
  • 33
  • 50

3 Answers3

0

First of all if you are using for each loop, then why you need to address it with row you can do it with $sections
For Ex

<td><?php echo $sections['ht_id'] ?></td> <td><?php echo $sections['Sections'] ?></td> <td><?php echo $sections['ht_descr'] ?></td>

And for the problem of undefined check the spelling of column name, you can debug and check the array of row.

Mahesh
  • 371
  • 3
  • 11
0

Just check if the index exists:

<?php 
if(isset($row[‘Sections’])) {
echo $row['Sections'] ;
}
?>
Michael Krutikov
  • 484
  • 1
  • 4
  • 10
0

If you are not sure that source array contains a "Section" key, then you can check it before print it:

echo isset($row['Sections']) ? $row['Sections'] : '';
Didax
  • 43
  • 5