0

I've been getting an Invalid argument warning for foreach and Undefined variable error for number, how could that be fixed? code shown below

<table class="table table-bordered">
  <thead>
    <tr>
      <td colspan='6'><h4><small>Online Players</small></h4></td>
    </tr>
    <td>Player Id</td>
    <td>Nickname</td>
    <td>Score</td>
    <td>Ping</td>
   </thead>

    <?php
    foreach($info as $number) //warning line
    {
      echo "<tr><td>".$number['PlayerID']."</td>";
      echo "<td>".$number['Nickname']."</td>";
      echo "<td>".$number['Score']."</td>";
      echo "<td>".$number['Ping']."</td></tr>";
    }
    if($number == 0)
    {
      echo "<tr><td colspan='6'><small>No players online or the database is too busy..</small></td></tr>";
    }
    ?>
</table>
Arend
  • 3,741
  • 2
  • 27
  • 37
Prabin
  • 33
  • 8
  • 2
    `$info` is not an array. that's all. – Joshua K Sep 11 '15 at 22:02
  • 2
    You need to show us where you define `$info` before using it in a `foreach ($array as $value)`, or if you haven't defined it previously than that's the problem. It's the declaration of `$info` that is the problem not the code you've posted. – DrewT Sep 11 '15 at 22:05
  • As mentioned above, $info is no where defined in your code snippet. – slik Sep 12 '15 at 00:35

0 Answers0