Error: Invalid argument supplied for foreach()

Asked

Viewed 3,068 times

1

I’m having a problem displaying my mailing list, is giving this error:

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

In the file it’s 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 ?>

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

  • $listaRecado is not an array, check its value.

  • places a print_r($listResults); and notes the return, as the comment above $listResults is not an array

  • Actually he’s pulling the $listRequired from the.php message, I’m pretty beginner.

1 answer

4


Check if the "$Listed Variables" 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;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.