3
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by Joshua Kidd
0

we can start here:

$strMiddleColumnValue = "0";
echo trim($strMiddleColumnValue) == "0"?"NONE":$strMiddleColumnValue;
0

Okay this works, but not replacing the "0". I have uploaded the file to my server and this is what I got.

http://www.globalvirtualairlines.com/MyPages/web%20app.php

Here is the code for my loop too get data from the XML, and this is a table.

<td><center><?php if($xml === false)
{
	echo "There was an error opening the xml file.";
	exit;
}
else
{
	foreach($xml as $pilot_totalflights_flown)
	{
		echo $pilot_totalflights_flown->tflts . "<br>";
	}
}
?></center></td>

Here is where i put your code you gave me.

<td><center><?php if($xml === false)
{
	echo "There was an error opening the xml file.";
	exit;
}
else
{
	foreach($xml as $pilot_totalflights_flown)
	{
		$strMiddleColumnValue = "0";
		echo trim($strMiddleColumnValue) == "0"?"NONE":$strMiddleColumnValue;
		echo $pilot_totalflights_flown->tflts . "<br>";
	}
}
?>
0
<td><center><?php if($xml === false){
	echo "There was an error opening the xml file.";
	exit;
}else{
	foreach($xml as $pilot_totalflights_flown)	{
		echo $pilot_totalflights_flown->tflts . "<br>";
	}
}
?></center></td>

This looks like you've got a single cell with all the data separated by a <br />.
Where does all the other data come from?
Don't tell me you have similar code for the rest of the columns.
You need to do a loop ACROSS rather than DOWN. This means you can target the fourth value [position 3 within the row (0,1,2,3)] and just run the replacement on that.

I assume the following xml as an array of items (rows) in the $data array:

foreach($data as $row){
  $first = $row[0];
  $last = $row[1];
  $status = $row[2];
  $flights = (intval($row[3]) == 0) ? 'NONE' : $row[3];
  $rating = $row[4];
  $country = $row[5];

  echo "<tr><td>$first</td><td>$last</td><td>$status</td><td>$flights</td><td>$rating</td><td>$country</td></tr>";
}

Edited by diafol: n/a

0

Here is where I get my XML data from: http://www.vafinancials.com/web/roster_xml.php?id= 18686

And yes I do have similar code for the other columns, such as country: I just change:

foreach($xml as $pilot_totalflights_flown)	{
		echo $pilot_totalflights_flown->tflts . "<br>";

to:

foreach($xml as $pilot_country)	{
		echo $pilot_country->cn . "<br>";

Here is a page I made to show you the tags such as | cn | tflts | etc...
http://www.globalvirtualairlines.com/MyPages/XMLdata.html

0

When I try this:

<?php foreach($xml as $row){
	  $pilot_first_name->fn = $row[0];
	  $pilot_last_name->ln = $row[1];
	  $pilot_status->sta = $row[2];
	  $pilot_totalflights_flown->tflt = (intval($row[3]) == 0) ? 'NONE' : $row[3];
	  $pilot_rating->rating = $row[4];
	  $pilot_country->cn = $row[5];

	  echo "<table><tr><td>$pilot_first_name</td><td>$pilot_last_name</td><td>$pilot_status</td><td>$pilot_totalflights_flown</td><td>$pilot_rating</td><td>$pilot_country</td></tr></table>";
	}
	?>

Obviously I did edit the original.
It gives me a crap load of errors all the same as this but throughout the whole page and it is the exact same:

Warning: main() [function.main]: Cannot add element pilot number 1 when only 0 such elements exist in C:\xampp\htdocs\web app.php on line 173

Warning: main() [function.main]: Cannot add element pilot number 2 when only 0 such elements exist in C:\xampp\htdocs\web app.php on line 174

Warning: main() [function.main]: Cannot add element pilot number 3 when only 0 such elements exist in C:\xampp\htdocs\web app.php on line 175

Warning: main() [function.main]: Cannot add element pilot number 4 when only 0 such elements exist in C:\xampp\htdocs\web app.php on line 176

Warning: main() [function.main]: Cannot add element pilot number 5 when only 0 such elements exist in C:\xampp\htdocs\web app.php on line 177

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.