Jump to content

back to basics, what am i missing?


dflow

Recommended Posts

nothing is echoed

for the second foreach??? :confused: :confused:

foreach($pictures as $picture)

-im breaking cause it's a large file

 

 

$doc = new DOMDocument();
$doc->load('accommodation.xml');

$i = 0;

$accommodations = $doc->getElementsByTagName('accommodation');
foreach($accommodations as $accommodation) {
if(++$i > 2) break;
$supplierID = $accommodation->getElementsByTagName('code')->item(0)->nodeValue;
$pictures = $accommodation->getElementsByTagName('pictures')->item(0)->nodeValue;
$pictures=array();
foreach($pictures as $picture) {
	 echo $url = $picture->getElementsByTagName('url')->item(0)->nodeValue;

}



}//end


//XMl schema
<?xml version="1.0" encoding="utf-8"?>
<accommodations>
<accommodation>
<code>1</code>
<pictures>
<picture>
<url>http://example.com/images.k.jpg</url>
</picture>
</pictures>

Link to comment
https://forums.phpfreaks.com/topic/256462-back-to-basics-what-am-i-missing/
Share on other sites

correct, they're trying to set a variable and echo it at the same time.

 

if you need that set to the $url variable, do this:

<php
$url = $picture->getElementsByTagName('url')->item(0)->nodeValue;
echo $url
?>

 

otherwise do what danny said.

  Quote

correct, they're trying to set a variable and echo it at the same time.

 

if you need that set to the $url variable, do this:

<php
$url = $picture->getElementsByTagName('url')->item(0)->nodeValue;
echo $url
?>

 

otherwise do what danny said.

still nada

var dump your object to make sure it's set and the structure is what you are using

 

<?php var_dump($picture->getElementsByTagName('url')->item(0)->nodeValue);?>

and see if it has anything.

 

if not,

<?php var_dump($picture); ?>

 

if it's empty, you have a deeper problem, if it's not empty, you're not following the children properly, so just go one by one until you find the mistake.

  Quote

var dump your object to make sure it's set and the structure is what you are using

 

<?php var_dump($picture->getElementsByTagName('url')->item(0)->nodeValue);?>

and see if it has anything.

 

if not,

<?php var_dump($picture); ?>

 

if it's empty, you have a deeper problem, if it's not empty, you're not following the children properly, so just go one by one until you find the mistake.

they are empty

i var_dumped($picture)

$picture=array(); does not set it as an array

when doing this:

var_dump($pictures = $accommodation->getElementsByTagName('pictures')->item(0)->nodeValue);

i get results??

 

for $picture to be empty and

 

$picture[/size][/color]->[/size][/color]getElementsByTagName[/size][/color]([/size][/color]'url'[/size][/color])->[/size][/color]item[/size][/color]([/size][/color]0[/size][/color])->[/size][/color]nodeValue

to have results, something is wrong, did you try the var_dump in the same exact place?

 

 

$picture should be an object, not an array - why are you trying to make it an array?

you said you get results, but what. what var dump says specifically is very useful in debugging why your echo isn't working. maybe it's an object or something?

 

 

so copy paste the exact result of the var dump of [/size][/color]$picture[/size][/color]->[/size][/color]getElementsByTagName[/size][/color]([/size][/color]'url'[/size][/color])->[/size][/color]item[/size][/color]([/size][/color]0[/size][/color])->[/size][/color]nodeValue

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.