Error: Invalid argument supplied for foreach ()

2

I'm having a problem displaying my scrapbook, giving this error:

Warning: Invalid argument supplied for foreach() in /###/###/###/view/list.php on line 11

The file looks like this:

<div class="container marketing">

    <?php foreach ($listaRecados as $r): ?>
      <div class="row featurette">
        <div class="col-md-12">
          <h2 class="featurette-heading"><?php echo $r->titulo; ?></span></h2>
          <p class="lead"><?php echo $r->texto; ?></p>
          <a href="recado.php?action=excluir&id=<?php echo $r->id; ?>"><span class="glyphicon glyphicon-trash"></span></a>
          <a href="recado.php?action=curtir&id=<?php echo $r->id; ?>"><span class="glyphicon glyphicon-thumbs-up"></span></a> <?php echo $r->likes; ?> - <?php echo $r->autor; ?>
        </div>
      </div>

      <hr class="featurette-divider">
    <?php endforeach ?>

Line 12 is this: <?php foreach ($listaRecados as $r): ?>

    
asked by anonymous 26.10.2017 / 18:36

1 answer

3

Make sure you know the variable "$ listRecords" you are calling and exactly an Array, use empty () to do this check.

 if(!empty($listaRecados)): foreach($listaRecados as $r): endforeach; else: echo "Array Vazio" endif;
    
27.10.2017 / 02:17