Jump to content

[SOLVED] Foreach Help


topflight

Recommended Posts

I am reccevie the following error:

Warning: Invalid argument supplied for foreach() in /home/mysite/public_html/mypage.php on line 22

 

 

<?php
require_once("VatsimPHPgenerator.php");
$VatsimPHP=new VatsimPHP;
?> 

<?php
$clientlist=$VatsimPHP->pilots();
?> 

<?php
$clientlist=$VatsimPHP->airline(array("ASA", "QXE"));
?>


<table width="100%" bgcolor="#DDDDDD">
<tr><td colspan=4 align=center bgcolor=#EEEEEE>No People Online</td>
</tr>



<table width="100%" cellpadding="0" align="left" bgcolor="#dddddd" >
<? foreach($clientlist as $client)
    { 
    echo"<tr>";
        echo"<td colspan=4 bgcolor=#EEEEEEalign=center>".$client[2]."</td>";
        echo"<td colspan=4 bgcolor=#EEEEEEalign=center>".$client[0]."</td>";     
        echo"</tr>";
      
    }
        ?>                                                                               
    </table>

 

This is line 22:

<?php foreach($clientlist as $client) ?>

 

Thanks in advanced.

 

 

Link to comment
https://forums.phpfreaks.com/topic/159954-solved-foreach-help/
Share on other sites

Well I am basically getting information from a source online and I notice when I put a different airline prefix in, it worked because there are like a lot airline connected to that network. But I do want to know how can I count that information for instance if it =0 then say nobody is online, so I wont receive that error.

Link to comment
https://forums.phpfreaks.com/topic/159954-solved-foreach-help/#findComment-843646
Share on other sites

Well I am basically getting information from a source online and I notice when I put a different airline prefix in, it worked because there are like a lot airline connected to that network. But I do want to know how can I count that information for instance if it =0 then say nobody is online, so I wont receive that error.

 

If what you mean is when the '$clientlist' is 0 then don't display the table, then you could do:

 

</pre>
<table width="100%" cellpadding="0" align="left" bgcolor="#dddddd">

if(count($clientlist) == 0)
{
   foreach($clientlist as $client)
   {
      echo "";
      echo "" . $client[2] . "";
      echo "" . $client[0] . "";     
      echo "";
     
    }
   else
   {
      echo "";
      echo "Sorry, no clients.";
      echo "";
   }
}
?>                                                                               

</

 

NOTE - Never use short tags, always use '<?php', to increase portability.

Link to comment
https://forums.phpfreaks.com/topic/159954-solved-foreach-help/#findComment-843653
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.