Selecting first node...

Discussion in 'PHP' started by thor22, Dec 19, 2008.

  1. #1
    Ok, I have this statement, and it returns multiple items. I only want the first item....

    foreach($response->Items->Item as $current){
      print("<a href=".$current->DetailPageURL."><img src='images/watch.gif' align='center'/></a><br/>");
     }	
    Code (markup):

    I tried this with no luck....

    foreach($response->Items->Item[1] as $current){
      print("<a href=".$current->DetailPageURL."><img src='images/watch.gif' align='center'/></a><br/>");
     }	
    Code (markup):
     
    thor22, Dec 19, 2008 IP
  2. juust

    juust Peon

    Messages:
    214
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    foreach($response->Items->Item as $current){
      print("<a href=".$current->DetailPageURL."><img src='images/watch.gif' align='center'/></a><br/>");
      break;
     }
    
    PHP:
    break just interrupts whatever loop you are in.
     
    juust, Dec 19, 2008 IP