graham23s Posted September 26, 2010 Share Posted September 26, 2010 Hi Guys, I'm getting a bit muddled with a loop here lol, what i'm trying to do is loop out the last 10 poular products from mysql and query amazon: <?php // Start the table print "<table width=\"90%\" align=\"center\" border=\"0\" cellpadding=\"2\" cellspacing=\"2\" />"; // Credentials $PublicKey = ""; $PrivateKey = ""; // Get the stored keywords for this category $qI = mysql_query("SELECT * FROM `fcs_products_viewed` LIMIT 10"); while ($aI = mysql_fetch_array($qI)) { $pID = $aI['product_unique_id']; // Prarameters we need to send to the function $parameters = array( 'Operation' => 'ItemLookup', //'SellerId' => 'A23I0F0MWQH94Z', //'Keywords' => 'potter', //'SearchIndex' => 'DVD', //Books for example. //"$searchparameter"=> $searchparameterdata , //'ItemPage' => 1, //which page? //'Service' => 'AWSECommerceService' , //this makes it version 4 //'SubscriptionId' => $subscriptionid , //is this correct? //'AWSAccessKeyId' => $awsaccesskeyid , //is this correct? 'ItemId' => $pID, //'ResponseGroup' => 'Medium' , //Small, Medium or Large 'ResponseGroup' => 'Medium' //Small, Medium, Large or SellerListing ); } // End while loop // Execute the function to return our URL $url = amazon_signed_request("co.uk", $parameters, $PublicKey, $PrivateKey); //print $url; // Load the results and get the contents $response = simplexml_load_file($url); // Pagination numbers $totalPages = $response->Items->TotalPages; //print $totalPages; // Loop through the xml nodes foreach ($response->Items->Item as $item) { // We need a function to check what ID number we need //$identificationNumber = amazon_id_number($catName); // All products so far seem to have an ASIN number which will be the identifier $title = $item->ItemAttributes->Title; $price = $item->OfferSummary->LowestNewPrice->FormattedPrice; $asin = $item->ASIN; $img_src = $item->SmallImage->URL; // Cut the title string if it's mega long if (strlen($title) > 100) { $title = substr($title, 0, 99); } // Clean symbols from the titles $titlesCleaned = amazon_strip_symbols($title); // Replace that stupid symbol $newprice = str_replace("Â", " ", $price); //print $itemID ; $amazonDisplay = "<form action=\"cart.php?add=Add\" method=\"POST\" name=\"fcsProductBox\" /> <input type=\"hidden\" name=\"fcsCartTriggered\" value=\"1\" /> <input type=\"hidden\" name=\"fcsCartProductId\" value=\"$asin\" /> <input type=\"hidden\" name=\"fcsCartProductQT\" value=\"1\" /> <input type=\"hidden\" name=\"fcsCartVendor\" value=\"amazon\" /> <table class=\"prod\"> <tr> <td valign=\"top\" class=\"pic\"><img src=\"$img_src\" border=\"0\" alt=\"$titlesCleaned\"></td> <td class=\"desc1\"> <div> <h3>".amazon_friendly_url($titlesCleaned, $asin)."</h3> <p><b>".amazon_friendly_url($titlesCleaned, $asin)."</b></p> <p>" . word_wrap_amazon_product_description($asin) . "</p> </div> </td> </tr> <tr> <td class=\"price\">$newprice</td> <td class=\"add-inf\"><input type=\"image\" img src=\"img/img-add-to-cart.png\" title=\"Add this item to your shopping cart\"></td> </tr> </table> </form>"; if ($x == 0){ print("<tr>\n<td valign=\"center\" align=\"center\">$amazonDisplay</td>\n"); } elseif ($x == 2) { print("<td valign=\"center\" align=\"center\">$amazonDisplay</td></tr>\n"); } else { print("<td valign=\"center\" align=\"center\">$amazonDisplay</td>\n"); } // Use some basic math to determine how many to show per line $x++; $x = $x % 2; } print "</tr></table>\n"; //} ?> i have a while() loop to get the last 10 products, but i need to use a foreach() at the same time to get the detaisl from amazon the way i have it now only loops 1 item. any help would be appreciated thanks guys Graham Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.