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
Share on other sites

For some weird reason it works now lol :) thanks

 

Hmm that's weird.  Be careful, it may just be for a specific case you just tested with or something.  But you're welcome, lol.

Link to comment
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.