Jump to content

Looping Data


graham23s

Recommended Posts

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

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.