Skip to content
Advertisement

Simple HTML DOM Parser – Problem displaying a variable inside foreach loop

I have created a simple PHP script using the simple_html_dom.php class. I fetch some information about movies from a website. I have one foreach loop inside another foreach loop. When I try to display the moviename inside the foreach loop I get the last moviename. What I want to achieve is to get each one of the unique movienames in each item. The problem is with the $movie variable.

(When i echo the $movie var on line 27 i get the correct result but I want to have each moviename inside the youtube links on line 33…)

JavaScript

ORIGINAL SOURCE:

JavaScript

How it’s now:

The HTML code that replaces the IMG elements and the problem being that the links are the same for ALL elements, when they should be Unique for each element like the MovieTitles:

JavaScript

Advertisement

Answer

The image you want is nested in one of the siblings of the detName DIV. So you can search for it by searching within the parent element.

Since find() allows more complex CSS selectors, you can search specifically for the image you want, rather than looping through all the images.

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement