PHP Nested Loop Produces Redundant Records....

Thread Solved

Join Date: Mar 2008
Posts: 36
Reputation: lonestar23 is an unknown quantity at this point 
Solved Threads: 0
lonestar23 lonestar23 is offline Offline
Light Poster

PHP Nested Loop Produces Redundant Records....

 
0
  #1
Nov 18th, 2008
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

  1. <?php
  2. $display_number = 15;
  3.  
  4. $tmp .= '<table width="100%" border="1" cellspacing="1" cellpadding="1">';
  5.  
  6. for ($i = 1; $i <= $display_number; $i++) { //this is the outer loop
  7.  
  8. $tmp .= $i;
  9.  
  10. #$thumb = $data['ysearchresponse']['resultset_images']['result'][$i]['thumbnail_url'];
  11.  
  12. $tmp .= "<tr>";
  13. $tmp .= "<td>".$i."</td>";
  14.  
  15. for($j = 1; $j <= 3; $j++) { // inner loop
  16.  
  17. $thumb = $data['ysearchresponse']['resultset_images']['result'][$i]['thumbnail_url'];
  18.  
  19. $tmp .= "<td>";
  20. #$tmp .= $i * $j;
  21. $tmp .= '<img src="';
  22. $tmp .= $thumb;
  23. $tmp .= '"/>';
  24. $tmp .= $title;
  25. $tmp .= "</td>";
  26. }
  27.  
  28. $tmp .= "</tr>";
  29. }
  30. $tmp .= '</table>';
  31. ?>
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: PHP Nested Loop Produces Redundant Records....

 
0
  #2
Nov 19th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 36
Reputation: lonestar23 is an unknown quantity at this point 
Solved Threads: 0
lonestar23 lonestar23 is offline Offline
Light Poster

Re: PHP Nested Loop Produces Redundant Records....

 
0
  #3
Nov 19th, 2008
ok I have formatted the results. Let me know if that will work.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: PHP Nested Loop Produces Redundant Records....

 
1
  #4
Nov 19th, 2008
here is something i would use to display 3 images to a row. maybe you can modify it.

  1. <?php
  2.  
  3. $table = '<table width="100%" border="1" cellspacing="1" cellpadding="1"><tr>';
  4.  
  5. $i = 0;
  6. foreach( $data['ysearchresponse']['resultset_images']['result'] as $value ) {
  7. if ( $i == 3 ) {
  8. $table .= '</tr><tr>';
  9. $i = 0;
  10. }
  11. $table .= "<td><img src=\"{$value['thumbnail_url']}\" /></td>";
  12. $i++;
  13. }
  14.  
  15. $table .= '</tr></table>';
  16.  
  17. ?>

there are a lot of unknown factors behind your code, so i kept it simple.
Last edited by kkeith29; Nov 19th, 2008 at 12:50 am. Reason: forgot the freakin code. i am loosing it.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 36
Reputation: lonestar23 is an unknown quantity at this point 
Solved Threads: 0
lonestar23 lonestar23 is offline Offline
Light Poster

Re: PHP Nested Loop Produces Redundant Records....

 
0
  #5
Nov 19th, 2008
i am not sure where your sample code is....
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: PHP Nested Loop Produces Redundant Records....

 
0
  #6
Nov 19th, 2008
its there now. somehow i forgot to post it. sorry.
Last edited by kkeith29; Nov 19th, 2008 at 12:50 am.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 36
Reputation: lonestar23 is an unknown quantity at this point 
Solved Threads: 0
lonestar23 lonestar23 is offline Offline
Light Poster

Re: PHP Nested Loop Produces Redundant Records....

 
0
  #7
Nov 19th, 2008
ok , got, will try it out, and post my results! Thanks!
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 36
Reputation: lonestar23 is an unknown quantity at this point 
Solved Threads: 0
lonestar23 lonestar23 is offline Offline
Light Poster

Re: PHP Nested Loop Produces Redundant Records....

 
0
  #8
Nov 19th, 2008
Keith, the code works wonderfully! Thanks again! Cheers!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum


Views: 691 | Replies: 7
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC