<html>
<head>
<style type="text/css">
table { width: 400px ; font-family: Verdana, Tahoma, Helevetica, Arial, sans-serif; font-size: 80%}
ul { list-style-type:none; line-height:166% }
</style>
</head>
<body>
<?php
// Set Local variables
$dev_token = "D3JONB1AX0R25J";

/* IF SEARCHING, GET STRING VALUES
$search = "";
$searchi = $_REQUEST['search'] . " "; //grab keywords from Querystring
$blown = explode(" ", $searchi);
$g = count($blown);
for ($h=0; $h < $g; $h++) {
    $search .= $blown[$h] . "%20";
}*/

$xml = "";
$key = "";
$values = "";

// Set Amazon variables
$ProductName = "";
$ImageURL = "";
$OurPrice = "";
$AmazonURL = "";

// Build Amazon XML Query URL
$URL = "http://xml.amazon.com/onca/xml3?t=webservices-20" .
       "&dev-t=" . $dev_token .
       "&KeywordSearch=" . "johnny%20cash" .
       "&mode=music" .
       "&type=lite" .
       "&page=1" .
       "&sort=+salesrank" .
       "&f=xml";

//print $URL;             // Uncomment this line to see the URL

// Get Amazon XML Query Results
$aurl=fopen($URL,"r");

while (!feof ($aurl))

    $xml .= fgets($aurl, 4096);

fclose ($aurl);

// Start the built-in XML parser
$parser = xml_parser_create(  );
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);

// Set tag names and values
xml_parse_into_struct($parser,$xml,$values,$index);

// Close down XML parser
xml_parser_free($parser);
?>
<table border="0" cellspacing="0" cellpadding="5" width="400" >
<tr><td>
<strong>Top 10 Selling Johnny Cash Albums:</strong><br />
<ul>
<?
for ($i=0; $i < 10; $i++) {

foreach ($index as $key=>$val) {
    switch ($key) {
      case "Asin":
          $Asin = $values[$val[$i]]['value'];
          break;
      case "ProductName":
          $ProductName = $values[$val[$i]]['value'];
          break;
      case "Artist":
          $Artist = $values[$val[$i]]['value'];
          break;
      case "ImageUrlMedium":
          $ImageURL = $values[$val[$i]]['value'];
          break;
      case "OurPrice":
          $OurPrice = $values[$val[$i]]['value'];
           break;
    }
}
$k = $i + 1;
?>
<li><a href="http://www.amazon.com/o/ASIN/<?= $Asin ?>/"><?= $ProductName ?></a><br />
      <?= $Artist ?>   Price: <?= $OurPrice ?></li>
<?
}
?>
</ul></td></tr>
</table>
</body>
</html>