...

View Full Version : Select one row of an array where item number is ..?



oskare100
12-30-2006, 01:15 PM
Hello,
When I call the Ebays XML API I get an array or something similar back (see the code sample), is it possible to "select item_id where item_id = 123123" or something similar as in MySQL? If, How can I do that? Also, I need to attach a PHP variables to the row I selected as for example $starttime, $endtime and so on.

Here is the code sample (the end of the scritpt);

<?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[2]->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
}

Best Regards
Oskar R

Linark
12-30-2006, 01:56 PM
If it is coming back as a (php) array you should be able to use:

$the_array['YourItemCodeHere']

Darklord
12-30-2006, 02:03 PM
Well, It seems that your particular question is how can I make an sql call to get all the information I need.

If this is the case, $result=mysql_query(Select info1,info2,info3 from Table WHERE something=something);

That is the basic syntax.
This will reveal a resource so you will also need to do something like mysql_fetch_row or mysql_fetch_array, there really is no difference when applying it in this manner. In other manners fetch row will return the rows affected whereas array will return full results.

So if we use this: $row=mysql_fetch_row($result);
$row['info1'] will equal info1 from the sql call and so on.

I hope this helps, if not, could you clear it up, Im shooting at what I think you need.

xconspirisist
12-30-2006, 02:37 PM
Please print the result of:


print_r($itemNodes);

Then we will know what $itemNodes is, and it's structure. From there we will be able to tell you how to itterate over it.

oskare100
12-30-2006, 04:09 PM
Well, It seems that your particular question is how can I make an sql call to get all the information I need.

If this is the case, $result=mysql_query(Select info1,info2,info3 from Table WHERE something=something);

That is the basic syntax.
This will reveal a resource so you will also need to do something like mysql_fetch_row or mysql_fetch_array, there really is no difference when applying it in this manner. In other manners fetch row will return the rows affected whereas array will return full results.

So if we use this: $row=mysql_fetch_row($result);
$row['info1'] will equal info1 from the sql call and so on.

I hope this helps, if not, could you clear it up, Im shooting at what I think you need.

Hello,
Thanks for your reply. The MySQL thing was only to compare what I want to do with something, the items returned are from Ebays XML API. Would it work to do something similar with the XML array return from Ebay?

/Oskar

oskare100
12-30-2006, 04:18 PM
Please print the result of:


print_r($itemNodes);

Then we will know what $itemNodes is, and it's structure. From there we will be able to tell you how to itterate over it.

Hello,
If I input the name of one auction I get the following results;


Array ( [0] => domelement Object ( [type] => 1 [tagname] => Item [0] => 6 [1] => 144398648 ) )

And if I input just a search term I get the follwing results;


Array ( [0] => domelement Object ( [type] => 1 [tagname] => Item [0] => 6 [1] => 143954024 ) [1] => domelement Object ( [type] => 1 [tagname] => Item [0] => 7 [1] => 143987448 ) [2] => domelement Object ( [type] => 1 [tagname] => Item [0] => 8 [1] => 144041536 ) ) Array ( [0] => domelement Object ( [type] => 1 [tagname] => Item [0] => 6 [1] => 143954024 ) [1] => domelement Object ( [type] => 1 [tagname] => Item [0] => 7 [1] => 143987448 ) [2] => domelement Object ( [type] => 1 [tagname] => Item [0] => 8 [1] => 144041536 ) ) Array ( [0] => domelement Object ( [type] => 1 [tagname] => Item [0] => 6 [1] => 143954024 ) [1] => domelement Object ( [type] => 1 [tagname] => Item [0] => 7 [1] => 143987448 ) [2] => domelement Object ( [type] => 1 [tagname] => Item [0] => 8 [1] => 144041536 ) )

Thanks in advance,
/Oskar



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum