SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Select one "item" of all items the php script returns..

    Hello,
    I'm trying to build a Ebay API system to leave feedback (I still need help with that in thread http://www.sitepoint.com/forums/show....php?p=3219996 in the PHP section) but here is another more specific question about XML.

    This is how the code sample I got from ebay look like;
    PHP Code:
    (The end of the file for the search code sample, full info about the function I want to use can be found at http://developer.ebay.com/DevZone/XML/docs/Reference/eBay/io_GetFeedback.html)

            else //no errors
            {
                //get results nodes
                $itemNodes = $responseDoc->get_elements_by_tagname('Item');
                
                //see if there are any results
                if(count($itemNodes) > 0)
                {
                ?>
                    <TABLE cellpadding="6" cellspacing="0" border="0">
                        <TR bgcolor="#BBBBBB">
                            <TD><B>Id</B></TD>
                            <TD><B>Title</B></TD>
                            <TD><B>Price</B></TD>
                            <TD><B>Started</B></TD>
                            <TD><B>Ends</B></TD>
                        </TR>
                <?php
                    
    //stores the alternationg background colour of the rows
                    
    $bgColor "#FFFFFF";
                    
    //go through each result
                    
    foreach($itemNodes as $item)
                    {
                        
    //get the required nodes from the results
                        
    $itemID $item->get_elements_by_tagname('ItemID');
                        
    $title $item->get_elements_by_tagname('Title');
                        
    $price $item->get_elements_by_tagname('CurrentPrice');
                        
    $startTime $item->get_elements_by_tagname('StartTime');
                        
    $endTime $item->get_elements_by_tagname('EndTime');
                        
    $link $item->get_elements_by_tagname('ViewItemURL');
                        
    //display the result in a table row
                        
    ?>
                        <TR bgcolor="<?php echo $bgColor ?>">
                            <TD><?php echo $itemID[0]->get_content(); ?></TD>
                            <!-- Display the Title as a link to the item on eBay -->
                            <TD><A href="<?php echo $link[0]->get_content(); ?>" target="_blank">
                                <?php echo $title[0]->get_content(); ?>
                                </A>
                            </TD>
                            <TD><?php echo $price[0]->get_content(); ?></TD>
                            <TD><?php echo $startTime[0]->get_content(); ?> GMT</TD>
                            <TD><?php echo $endTime[0]->get_content(); ?> GMT</TD>
                        </TR>
                        <?php
                        
    //alternate the background colours
                        
    $bgColor $bgColor == "#FFFFFF" "#EEEEEE" "#FFFFFF";
                    } 
    ?>
                    </TABLE>
                    <?php
                
    }
                else
                {
                    echo 
    '<P><B>No items found</B>';
                }
            }
        }
    ?>
    Is it possible to just select one or two of the items the script is returning and add variables as for example $item_id and so on to the selected item?

    Thanks in advance,
    /Oskar

  2. #2
    SitePoint Evangelist ikeo's Avatar
    Join Date
    Oct 2004
    Location
    Austin Texas
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sure.

    You could just check for the item you want and process when you find it ....
    so in the foreach loop
    PHP Code:
    $itemID $item->get_elements_vy_tagname('ItemID')
    if( 
    $itemID[0]->get_content() == "what i want")
    {
      
    //Then Process;



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •