I am having problems retrieving distinct records from a XML record. I am using the following code but seem to have the same image in an entire row. Thanks in Advance!

view demo code demo

$display_number = 15;

$tmp .= '<table width="100%" border="1" cellspacing="1" cellpadding="1">';

for ($i = 1; $i <= $display_number; $i++) {   //this is the outer loop

$tmp .= $i;

#$thumb =  $data['ysearchresponse']['resultset_images']['result'][$i]['thumbnail_url'];

  $tmp .= "<tr>";
  $tmp .= "<td>".$i."</td>";

 for($j = 1; $j <= 3; $j++) { // inner loop
 $thumb =  $data['ysearchresponse']['resultset_images']['result'][$i]['thumbnail_url'];
       $tmp .= "<td>";
		#$tmp .= $i * $j;
	   $tmp .= '<img src="';	
	   $tmp .= $thumb;
	   $tmp .= '"/>';
	   $tmp .= $title;
	   $tmp .= "</td>";

   $tmp .= "</tr>";
$tmp .= '</table>';
9 Years
Discussion Span
Last Post by lonestar23

in the demo, you have printed the xml array. can you put <pre></pre> tags around it so its more readable? maybe after that, i can see how the array is formatted and see where you went wrong.


here is something i would use to display 3 images to a row. maybe you can modify it.


$table = '<table width="100%" border="1" cellspacing="1" cellpadding="1"><tr>';

$i = 0;
foreach( $data['ysearchresponse']['resultset_images']['result'] as $value ) {
	if ( $i == 3 ) {
		$table .= '</tr><tr>';
		$i = 0;
	$table .= "<td><img src=\"{$value['thumbnail_url']}\" /></td>";

$table .= '</tr></table>';


there are a lot of unknown factors behind your code, so i kept it simple.

Votes + Comments
Great Fix to a Loop that I could not figure out!
This question has already been answered. 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.