topflight Posted May 27, 2009 Share Posted May 27, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/159954-solved-foreach-help/ Share on other sites More sharing options...
Maq Posted May 27, 2009 Share Posted May 27, 2009 Can we see the airline() function? It should return an array. Quote Link to comment https://forums.phpfreaks.com/topic/159954-solved-foreach-help/#findComment-843628 Share on other sites More sharing options...
topflight Posted May 27, 2009 Author Share Posted May 27, 2009 I am confused what do you mean. This is a 3rd Party Script Quote Link to comment https://forums.phpfreaks.com/topic/159954-solved-foreach-help/#findComment-843633 Share on other sites More sharing options...
topflight Posted May 27, 2009 Author Share Posted May 27, 2009 For some weird reason it works now lol thanks Quote Link to comment https://forums.phpfreaks.com/topic/159954-solved-foreach-help/#findComment-843636 Share on other sites More sharing options...
Maq Posted May 27, 2009 Share Posted May 27, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/159954-solved-foreach-help/#findComment-843639 Share on other sites More sharing options...
topflight Posted May 27, 2009 Author Share Posted May 27, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/159954-solved-foreach-help/#findComment-843646 Share on other sites More sharing options...
Maq Posted May 27, 2009 Share Posted May 27, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/159954-solved-foreach-help/#findComment-843653 Share on other sites More sharing options...
topflight Posted May 27, 2009 Author Share Posted May 27, 2009 Well if equal zero it is still going to run that, I want it to have it setup so that if it does equal zero it will say the no clients online else if it doesn't it will run the script how can I do that? Quote Link to comment https://forums.phpfreaks.com/topic/159954-solved-foreach-help/#findComment-843661 Share on other sites More sharing options...
Maq Posted May 27, 2009 Share Posted May 27, 2009 if(count($clientlist) != 0) Quote Link to comment https://forums.phpfreaks.com/topic/159954-solved-foreach-help/#findComment-843665 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.