Jump to content

[SOLVED] Arrays Are In The Loop!


Crew-Portal

Recommended Posts

Okay I got my arrays set up so they look like:

 <tr>
   <td>" . $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN']['0']['STATUSTEXT']['0']['VALUE'] . "</td>
   <td>" . $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN']['0']['PLAYERNAME']['0']['VALUE'] . "</td>
   <td>" . $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN']['0']['TIMEFILEDTEXT']['0']['VALUE'] . "</td>
   <td>" . $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN']['0']['TIMEOPENED']['0']['VALUE'] . "</td>
   <td>" . $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN']['0']['TIMECLOSED']['0']['VALUE'] . "</td>
   <td>" . $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN']['0']['OPENTIMETEXT']['0']['VALUE'] . "</td>
 </tr>

but how would I go about setting this pattern up in a loop to get all of the arrays, and of course the ['0'] part in each array will change by going up one number... but if someone could enlighten me on how to stick the arrays in a for while statement that would be awesome!

Link to comment
Share on other sites

I do not have control over the size of the array because it is a dump from a video game, well not the array there was an XML dump but I used PHP to translate it over to an array. But how would I got about doing it s that it would increase 0 to 1 and 1 to 2 if there was that number in the array, like if it 4 to 5 and there was no 5 then it would roll back and stay at 4, just so that I can display the arrays nicely on a table.  ;D

Link to comment
Share on other sites

How to increase the number and check if it is valid.

Example:

<?php
$count = 0;
while($variable == $condition) {
      $count++;
      if (is_array($array[$count])) 
           // execute
}
?> 

 

This array is just has to many dimensions to be able to loop it out(completely), without timing out the script(will also take a while).

I suggest you just use the good old print_r function, it's your best bet if you want to view the whole array.

Link to comment
Share on other sites

By the looks of it you have a 4 dimensional array there (or more), so you need $i,$j,$k,$q to iterate your loop.

Sample :

for($i=0;$i<count($xml['FSHOST']);$i++{
  $flightplans = $xml['FSHOST'][$i]['FLIGHTPLANS'];

  for($j=0;$j<count($flightplans);$j++){
    $flightplan = $flightplans[$j]['FLIGHTPLAN'];

    for($k=0;$k<count($flightplan;$k++){
      $statustext = $flightplan[$k]['STATUSTEXT'][0]['VALUE'];
      $playername = $flightplan[$k]['PLAYERNAME'][0]['VALUE'];
      $timefiledtext = $flightplan[$k]['TIMEFILEDTEXT'][0]['VALUE'];
      $timeopened = $flightplan[$k]['TIMEOPENED'][0]['VALUE'];
      $timeclosed = $flightplan[$k]['TIMECLOSED'][0]['VALUE'];
      $opentimetext = $flightplan[$k]['OPENTIMETEXT'][0]['VALUE'];
    }

  }

}

 

By the way i'm making a HUGE assumption here, in that once you get to the flightplan it's only got 1 status, 1 playername, 1 timefiledtext, 1 timeopened, 1 timeclosed, 1 opentimetext .

 

You work out where you want your <tr><td> 's...

 

 

All i can say is that XML is REALLY badly formed and if you have PHP5+ consider using SimpleXMLElement instead of loops.

Link to comment
Share on other sites

I think I figured it out, but I wont know until someone connects to multiplayer later today. But heres what I got Maybe look it over and tell me if its okay?

<?php
echo"
<table width='80%' border='0'>
  <tr>
    <td colspan='6'>Open Flight Plans On Our Multiplayer Servers!</td>
  </tr>
  <tr>
    <td>Status:</td>
    <td>Player Name:</td>
<td>Time Filed:</td>
    <td>Time Opened:</td>
    <td>Time Closed:</td>
    <td>Total Time:</td>
  </tr>";
  $arraynum = '0';
  while (is_array($xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum])){
echo "
  <tr>
    <td>" . $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum]['STATUSTEXT'][$arraynum]['VALUE'] . "</td>
    <td>" . $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum]['PLAYERNAME'][$arraynum]['VALUE'] . "</td>
    <td>" . $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum]['TIMEFILEDTEXT'][$arraynum]['VALUE'] . "</td>
    <td>" . $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum]['TIMEOPENED'][$arraynum]['VALUE'] . "</td>
    <td>" . $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum]['TIMECLOSED'][$arraynum]['VALUE'] . "</td>
    <td>" . $xml['FSHOST']['0']['FLIGHTPLANS']['0']['FLIGHTPLAN'][$arraynum]['OPENTIMETEXT'][$arraynum]['VALUE'] . "</td>
  </tr>
";
$arraynum++;
}
echo "</table>";
?>

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.