Jump to content

Select one row of an array where item number is ..?


oskare100

Recommended Posts

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);
[code=php:0] <?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
}[/code]

Best Regards
Oskar R
Link to comment
Share on other sites

For the first part of your problem you could do something like this... I am using it on 2 of my sites at the minute...

$refer_id = 1234(what ever you want);

$sql = mysql_query("SELECT * FROM tblTable WHERE item_id='$refer_id'");
$data = mysql_fetch_array($sql);

//$data[item_ 1-5] are the values returned from the datatbase were each item is a header
$item_1 = $data[item_1];
$item_2 = $data[item_2];
$item_3 = $data[item_3];
$item_4 = $data[item_4];
$item_5 = $data[item_5];
$item_6 = $data[item_6];

/* Let's strip some slashes in case the user entered
any escaped characters. */
$item_id = stripslashes($item_id);
$item_1 = stripslashes($item_1);
$item_2 = stripslashes($item_2);
$item_3 = stripslashes($item_3);
$item_4 = stripslashes($item_4);
$item_5 = stripslashes($item_5);
$item_6 = stripslashes($item_6);

//tests results
print "This is item $item_1\n";
print "This is item $item_2\n";
print "This is item $item_3\n";
print "This is item $item_5\n";
print "This is item $item_6\n";

give it a go.....

kieron
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.