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

<?php
$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>';
?>

Recommended Answers

All 7 Replies

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.

ok I have formatted the results. Let me know if that will work.

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

<?php

$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>";
	$i++;
}

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

?>

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

commented: Great Fix to a Loop that I could not figure out! +1

i am not sure where your sample code is....

its there now. somehow i forgot to post it. sorry.

ok , got, will try it out, and post my results! Thanks!

Keith, the code works wonderfully! Thanks again! Cheers!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.