Advertisement
| Hall of Fame |
|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| Question |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: |
This provides a search box and passes that to create the url, then reads and outputs the XML using magicparser
<?php
require("MagicParser.php");
ini_set('user_agent', 'Opera - Opera/9.00 (Windows NT 5.1; U; en)');
if (!$_GET["q"]) $_GET["q"] = "Xseries";
print "<h1>Yahoo Shopping API</h1>";
print "<form method='GET'>";
print "<input type='text' name='q' value='".htmlentities($_GET["q"])."' /> ";
print "<input type='submit' value='Search' />";
print "</form>";
function myRecordHandler($item)
{
print "<h3><a href='".$item["URL"]."'>".$item["SUMMARY"]."</a></h3>";
print "<img src='".$item["GRIDIMAGE/URL"]."' />";
print "<p>".$item["PRODUCTNAME"]."</p>";
print "<p>".$item["DESCRIPTION"]."</p>";
print "<h4>UPC:".$item["UPC"]."</h4>";
print "<h4>Manufacturer:".$item["BRAND"]."</h4>";
print "<h4>Category:".$item["CATEGORY/TITLE"]."</h4>";
print "<h4>Pricing: $".$item["PRICEFROM"]. " - $".$item["PRICETO"]."</h4>";
$specificationLabel = "";
$specificationValue = "";
foreach($item as $key => $value)
{
if (strpos($key,"SPECIFICATIONLABEL")!==FALSE) $specificationLabel = $value;
if (strpos($key,"SPECIFICATIONVALUE")!==FALSE) $specificationValue = $value;
if ($specificationLabel && $specificationValue)
{
// use $specificationLabel and $specificationValue here
// reset for next pair
print "<ul>";
print "<li>".$specificationLabel." : ";
print $specificationValue."</li>";
print "</ul>";
$specificationLabel = "";
$specificationValue = "";
}
}
print "<br /><br />";
}
if ($_GET["q"])
{
// construct Yahoo Web Services Query URL
$url = "http://shopping.yahooapis.com/ShoppingService/V3/productSearch?";
$url .= "appid=YahooDemo";
$url .= "&class=catalogs";
$url .= "&query=".urlencode($_GET["q"]);
// fetch the response and parse the resultsz
MagicParser_parse($url,"myRecordHandler","xml|PRODUCTSEARCH/PRODUCTS/PRODUCT/CATALOG/");
}
?>
This php reads and outputs the existing csv file which I have specified it's format above.
<?php
// reads a csv file and returns a two-dimensional array of lines/fields
function read_csv($file,$delimiter)
{
$data_array = file($file);
for ( $i = 0; $i < count($data_array); $i++ )
{
$parts_array[$i] = explode($delimiter,$data_array[$i]);
}
return $parts_array;
}
// reads a csv file and returns an two-dimensional array of lines/fields
function select_csv($file,$delimiter,$field,$query)
{
$data_array = file($file);
for ( $i = 0; $i < count($data_array); $i++ )
{
$parts_array[$i] = explode($delimiter,$data_array[$i]);
if(trim(strtolower($parts_array[$i][$field])) == trim(strtolower($query)))
{
$result_array[] = $parts_array[$i];
}
}
return $result_array;
}
// ------------------- demonstration below --------------------
// this willl display all records in the csv file
$data = read_csv('read_csv.txt','|');
for ( $i = 0; $i < count($data); $i++ )
{
for ( $u = 0; $u < count($data[$i]); $u++ )
{
echo $data[$i][$u].' ';
if($data[$i][$u] == end($data[$i]))
{
echo '<br>';
}
}
}
echo '<p>';
// this willl display all records where the value
// of the selected field matches the query
$data = select_csv('read_csv.txt','|','0','32P0768');
for ( $i = 0; $i < count($data); $i++ )
{
for ( $u = 0; $u < count($data[$i]); $u++ )
{
echo $data[$i][$u].' ';
}
echo '<br>';
}
?>
|