Jump to content

having a bit of a challenge rearranging things properly...


Recommended Posts

Hello again,

 

First I must thank the community once again for the help on my other thread that helped me get to this stage, I am on my last step and Just need to arrange things properly. I am quite new at php and have spent many hours today trying to figure this one little thing out that probably might end up being something very easy to do as I found with my other issues that were solved.

 

Please visit http://development-zone.info/example.html and search for gold, or ps3 or xbox something popular in that nature, once you have searched for something you will be able to see my issue, I am having trouble figuring out how to output the sold count correctly. If anyone has any ideas on how to accomplish this please do share your insights.

 

Below is the code to,Hopefully someone can shed some light to this issue.

<?php

error_reporting(E_ALL);  // turn on all errors, warnings and notices for easier debugging


$query = $_POST['search'];  // You will need to supply your own query




$endpoint = 'http://open.api.ebay.com/shopping';  // URL to call
$responseEncoding = 'XML';                                       // Type of response we want back

// Construct the FindItems call 

$apicall = "$endpoint?callname=FindPopularItems&responseencoding=$responseEncoding&appid=ApiKeywhichisnotbeingusedforexample&siteid=0&QueryKeywords=$query&MaxEntries=5&version=725";

// Load the call and capture the document returned by eBay API


$resp = simplexml_load_file($apicall);

// Check to see if the response was loaded, else print an error
if ($resp) {
$results = '';
    
    // If the response was loaded, parse it and build links
    
$items = array();
foreach($resp->ItemArray->Item as $item) {
  $items[] = $item->ItemID;



}
$comma_separated_list = implode(',',$items);
// Construct the FindItems call 
$apicallb = "$endpoint?callname=GetMultipleItems&responseencoding=XML&appid=ApiKeywhichisnotbeingusedforexample&siteid=0&ItemID=$comma_separated_list&IncludeSelector=Details&version=725";

// Load the call and capture the document returned by eBay API
$Resp = simplexml_load_file($apicallb);

// Check to see if the response was loaded, else print an error
if ($Resp) {
$results2 = '';
    
    // If the response was loaded, parse it and build links  
    foreach($Resp->Item as $item2) {

        $qsold = $item2->QuantitySold;
        $itemsid4quantitysold = $item2->ItemID;

  
	// For each SearchResultItem node, build a link and append it to $results
	$results2 .= "ItemsID: $itemsid4quantitysold Q Sold: $qsold <br/>";
}
}
// If there was no response, print an error
else {
$results2 = "Oops! Must not have gotten the response!";
}






    foreach($resp->ItemArray->Item as $item) {
global $qsold;
        $link  = $item->ViewItemURLForNaturalSearch;
        $title = $item->Title;
        $watchcount = $item->WatchCount;
        $image = $item->GalleryURL;
        $itemids5 = $item->ItemID;

  
	// For each SearchResultItem node, build a link and append it to $results
	$results .= "<div id=\"container\">

<div id=\"image\">
<img src=\"$image\" />
</div>

<div id=\"tophalf\">
<center>
<p>  <span class=\"title\">$title</span> <br />

<span class=\"black\">Date this item ends for sale:</span><span class=\"red\">June.30.2011</span>
</p>
</center>
</div>

<div id=\"bottomhalf\">
<img src=\"itemswatched.jpg\" width=\"36\" height=\"31\" /> <span class=\"black2\">Items Watched by:<b>$watchcount</b> people. Items Sold:$qsold </span><img src=\"money.jpg\" width=\"50\" height=\"30\" /> <span class=\"black2\">Price:</span>$1.49 <br />Iditem:$itemids5
</div>


</div>";
}
}

// If there was no response, print an error
else {
$results = "Oops! Must not have gotten the response!";
}


?>

<!-- Build the HTML page with values from the call response -->
<html>
<head>
<link href="css.css" rel="stylesheet" type="text/css" />
<title>
eBay Search Results for <?php echo $query; ?>
</title>
</head>
<body>

<h1>eBay Search Results for <?php echo $query; ?></h1>
<form action="Sample_gmwi_gsi_grci_NV_XML.php" method="POST">
Search Popular ebay Items <input type="text" name="search" />
<input type="submit" />
</form> 

<?php echo $results2,$results;?>

<?php echo $comma_separated_list;?>
</body>
</html>

 

As you will see my current attempt is outputting only one item sold count repeatedly in "items Sold". I am using the ebay api by the way.

Thank you for your time and expertise.

Link to comment
Share on other sites

at a quick glance, you don't seem to be grabbing the quantity.

 

where you have this:

$link  = $item->ViewItemURLForNaturalSearch;
$title = $item->Title;
$watchcount = $item->WatchCount;
$image = $item->GalleryURL;
$itemids5 = $item->ItemID;

 

try adding:

 

$qsold = $item->QuantitySold;

Link to comment
Share on other sites

at a quick glance, you don't seem to be grabbing the quantity.

 

where you have this:

$link  = $item->ViewItemURLForNaturalSearch;
$title = $item->Title;
$watchcount = $item->WatchCount;
$image = $item->GalleryURL;
$itemids5 = $item->ItemID;

 

try adding:

 

$qsold = $item->QuantitySold;

 

Hi WebStyles,

Thanks for your reply,

The reason for me not having $qsold grabbing the QuantitySold in this piece of code is because this piece of code is apart of the

 $resp = simplexml_load_file($apicall);

Which does not return QuantitySold, I have to retrieve QuantitySold  from

$Resp = simplexml_load_file($apicallb);

I am using two ebay api calls to retrieve the needed information for this project. If any other information is needed please do ask, I will of course try and figure it out while I pick the brilliant minds at this great forum.

 

Link to comment
Share on other sites

Hi WebStyles,

Thank you for your idea, that sounds like something that can possibly work. I am new at php so please forgive me for that,I have spent some time trying this out and I am thinking perhaps I may have done what you suggested incorrectly as I keep failing to achieve results.

 

I hate to ask to hold my hand but perhaps maybe you can provide an example with my variables.

 

I have uploaded an image as a reference, I also have a question if this solution of yours will allow me to implement it into $results ? As you can see with $results its grabbing everything it needs to grab properly, if only I could place this with it. I am determined even though I am  :confused: ,It is now about to reach 6am and this has cost me to have no sleep during the night so I will retire for now to gain some rest.

 

Thank you once again very much for the assistance.

 

 

 

 

[attachment deleted by admin]

Link to comment
Share on other sites

ok, try somthing like this:

 

right after $Resp = simplexml_load_file($apicallb); (around line 40)

add:

$itemID_and_quantity = array();

(just to start a new empty array)...

then inside your results loop (around line 48) where you have

foreach($Resp->Item as $item2) {

        $qsold = $item2->QuantitySold;
        $itemsid4quantitysold = $item2->ItemID;

add:

$itemID_and_quantity[$itemsid4quantitysold] = $qsold;

so it will now look like this:

foreach($Resp->Item as $item2) {

        $qsold = $item2->QuantitySold;
        $itemsid4quantitysold = $item2->ItemID;
$itemID_and_quantity[$itemsid4quantitysold] = $qsold;

then at the bottom, where you want to display it (around line 92/93) where you have:

 

<div id=\"bottomhalf\">
<img src=\"itemswatched.jpg\" width=\"36\" height=\"31\" /> <span class=\"black2\">Items Watched by:<b>$watchcount</b> people. Items Sold:$qsold </span><img src=\"money.jpg\" width=\"50\" height=\"30\" /> <span class=\"black2\">Price:</span>$1.49 <br />Iditem:$itemids5
</div>

 

replace $qsold with: {$itemID_and_quantity[$itemsid5]}

 

<div id=\"bottomhalf\">
<img src=\"itemswatched.jpg\" width=\"36\" height=\"31\" /> <span class=\"black2\">Items Watched by:<b>$watchcount</b> people. Items Sold:{$itemID_and_quantity[$itemsid5]} </span><img src=\"money.jpg\" width=\"50\" height=\"30\" /> <span class=\"black2\">Price:</span>$1.49 <br />Iditem:$itemids5
</div>

 

if the ids are the same, this should work.

Link to comment
Share on other sites

Hello again Webstyles,

 

I must first thank you very much for the effort you have provided me with, I am most grateful. I have added your suggestions into my code and updated.

<?php

error_reporting(E_ALL);  // turn on all errors, warnings and notices for easier debugging


$query = $_POST['search'];  // You will need to supply your own query




$endpoint = 'http://open.api.ebay.com/shopping';  // URL to call
$responseEncoding = 'XML';                                       // Type of response we want back

// Construct the FindItems call 

$apicall = "$endpoint?callname=FindPopularItems&responseencoding=$responseEncoding&appid=NoApiKey4Example&siteid=0&QueryKeywords=$query&MaxEntries=5&version=725";

// Load the call and capture the document returned by eBay API


$resp = simplexml_load_file($apicall);

// Check to see if the response was loaded, else print an error
if ($resp) {
$results = '';
    
    // If the response was loaded, parse it and build links
    
$items = array();
foreach($resp->ItemArray->Item as $item) {
  $items[] = $item->ItemID;



}
$comma_separated_list = implode(',',$items);
// Construct the FindItems call 
$apicallb = "$endpoint?callname=GetMultipleItems&responseencoding=XML&appid=NoApiKey4Example&siteid=0&ItemID=$comma_separated_list&IncludeSelector=Details&version=725";

// Load the call and capture the document returned by eBay API
$Resp = simplexml_load_file($apicallb);
    $itemID_and_quantity = array();

// Check to see if the response was loaded, else print an error
if ($Resp) {
$results2 = '';
    
    // If the response was loaded, parse it and build links  

    foreach($Resp->Item as $item2) {

        $qsold = $item2->QuantitySold;
        $itemsid4quantitysold = $item2->ItemID;
        $itemID_and_quantity[$itemsid4quantitysold] = $qsold;
  
	// For each SearchResultItem node, build a link and append it to $results

	$results2 .= "ItemsID: $itemsid4quantitysold Q Sold: $qsold <br/>";
}
}
// If there was no response, print an error
else {
$results2 = "Oops! Must not have gotten the response!";
}






    foreach($resp->ItemArray->Item as $item) {

        $link  = $item->ViewItemURLForNaturalSearch;
        $title = $item->Title;
        $watchcount = $item->WatchCount;
        $image = $item->GalleryURL;
        $itemids5 = $item->ItemID;


  
	// For each SearchResultItem node, build a link and append it to $results
	$results .= "<div id=\"container\">

<div id=\"image\">
<img src=\"$image\" />
</div>

<div id=\"tophalf\">
<center>
<p>  <span class=\"title\">$title</span> <br />

<span class=\"black\">Date this item ends for sale:</span><span class=\"red\">June.30.2011</span>
</p>
</center>
</div>

<div id=\"bottomhalf\">
<img src=\"itemswatched.jpg\" width=\"36\" height=\"31\" /> <span class=\"black2\">Items Watched by:<b>$watchcount</b> people. Items Sold:{$itemID_and_quantity[$itemsid5]}
</span><img src=\"money.jpg\" width=\"50\" height=\"30\" /> <span class=\"black2\">Price:</span>$1.49 <br />Iditem:$itemids5
</div>


</div>";
}
}

// If there was no response, print an error
else {
$results = "Oops! Must not have gotten the response!";
}


?>

<!-- Build the HTML page with values from the call response -->
<html>
<head>
<link href="css.css" rel="stylesheet" type="text/css" />
<title>
eBay Search Results for <?php echo $query; ?>
</title>
</head>
<body>

<h1>eBay Search Results for <?php echo $query; ?></h1>
<form action="Sample_gmwi_gsi_grci_NV_XML.php" method="POST">
Search Popular ebay Items <input type="text" name="search" />
<input type="submit" />
</form> 
<?php echo $results2;?>
<?php echo $results;?>

<?php echo $comma_separated_list;?>
<br />

</body>
</html>

 

However I am now getting the following;

Warning: Illegal offset type in /home/naruto/public_html/development-zone.info/Sample_gmwi_gsi_grci_NV_XML.php on line 54

Warning: Illegal offset type in /home/naruto/public_html/development-zone.info/Sample_gmwi_gsi_grci_NV_XML.php on line 54

Warning: Illegal offset type in /home/naruto/public_html/development-zone.info/Sample_gmwi_gsi_grci_NV_XML.php on line 54

Warning: Illegal offset type in /home/naruto/public_html/development-zone.info/Sample_gmwi_gsi_grci_NV_XML.php on line 54

Warning: Illegal offset type in /home/naruto/public_html/development-zone.info/Sample_gmwi_gsi_grci_NV_XML.php on line 54

Notice: Undefined variable: itemsid5 in /home/naruto/public_html/development-zone.info/Sample_gmwi_gsi_grci_NV_XML.php on line 98

Notice: Undefined index: in /home/naruto/public_html/development-zone.info/Sample_gmwi_gsi_grci_NV_XML.php on line 98

Notice: Undefined variable: itemsid5 in /home/naruto/public_html/development-zone.info/Sample_gmwi_gsi_grci_NV_XML.php on line 98

Notice: Undefined index: in /home/naruto/public_html/development-zone.info/Sample_gmwi_gsi_grci_NV_XML.php on line 98

Notice: Undefined variable: itemsid5 in /home/naruto/public_html/development-zone.info/Sample_gmwi_gsi_grci_NV_XML.php on line 98

Notice: Undefined index: in /home/naruto/public_html/development-zone.info/Sample_gmwi_gsi_grci_NV_XML.php on line 98

Notice: Undefined variable: itemsid5 in /home/naruto/public_html/development-zone.info/Sample_gmwi_gsi_grci_NV_XML.php on line 98

Notice: Undefined index: in /home/naruto/public_html/development-zone.info/Sample_gmwi_gsi_grci_NV_XML.php on line 98

Notice: Undefined variable: itemsid5 in /home/naruto/public_html/development-zone.info/Sample_gmwi_gsi_grci_NV_XML.php on line 98

Notice: Undefined index: in /home/naruto/public_html/development-zone.info/Sample_gmwi_gsi_grci_NV_XML.php on line 98

 

Very strange indeed I really thought your pieces of code were the answer to this issue(it looked very promising), perhaps I made a mistake somewhere? I am open to more suggestions if you or any other might want to give a crack at it.

 

[attachment deleted by admin]

Link to comment
Share on other sites

There's gotta be something else wrong. My code simply creates a new array and populates it with values you already had in other variables. the error is somewhere else.

 

Did you replace the API Key in your string? (the one you posted was removed for obvious reasons)

 

Did you change ANYTHING in the api calls ?

 

Go back to your code before you added my changes, and test again, then add the changes carefully, testing after adding each line, until you figure out where the error is.

 

 

 

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.