[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.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

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!

5.5

Pass csv data to query for XML data to combine in csv using PHP

Asked by websuperman in Extensible Markup Language (XML), PHP and Databases, MySQL Server

Tags: PHP, XML, MySQL, CSV, IE7

I have figured out various parts to the final outcome online.  I am just beginning to learn PHP.  I am trying to get the value of a field from a csv to pass to the creation of a URL which supplies an XML file and then pull certain information from that xml file to store with each returned value and then save in a csv file that is comma seperated with the fields enclosed in quotes.  The XML file looks like:
http://shopping.yahooapis.com/ShoppingService/V3/productSearch?appid=YahooDemo&class=catalogs&query=32P0768

I have created php to parse and display portions of the xml and to parse and display results from the existing csv but have no idea how to put them together.

Exisitng CSV file that will be read from to pass it's value to get xml data is:
SKU|MANUFACTURER|CATEGORY
32P0768|IBM|
92P1102|Lenovo|
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>';  
}
 
?>
[+][-]11/05/08 05:16 PM, ID: 22891690Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: Extensible Markup Language (XML), PHP and Databases, MySQL Server
Tags: PHP, XML, MySQL, CSV, IE7
Sign Up Now!
Solution Provided By: Ray_Paseur
Participating Experts: 1
Solution Grade: B
 
[+][-]10/31/08 11:54 AM, ID: 22853140Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/02/08 10:44 AM, ID: 22862607Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/03/08 07:35 AM, ID: 22867802Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/03/08 07:42 AM, ID: 22867866Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/03/08 08:00 AM, ID: 22868048Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/03/08 08:06 AM, ID: 22868115Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/03/08 08:10 AM, ID: 22868159Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/03/08 08:13 AM, ID: 22868188Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/03/08 09:05 AM, ID: 22868729Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/03/08 01:52 PM, ID: 22871602Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/03/08 01:56 PM, ID: 22871638Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/03/08 02:01 PM, ID: 22871689Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/03/08 02:22 PM, ID: 22871880Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/03/08 03:44 PM, ID: 22872478Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/03/08 09:17 PM, ID: 22873703Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/04/08 10:00 AM, ID: 22878719Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/04/08 10:10 AM, ID: 22878823Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/08 12:56 PM, ID: 22880662Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/04/08 02:05 PM, ID: 22881383Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/04/08 02:08 PM, ID: 22881410Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/08 11:00 AM, ID: 22888597Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/05/08 01:38 PM, ID: 22890269Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/05/08 03:39 PM, ID: 22891254Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/10/08 12:59 PM, ID: 22925480Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/10/08 01:06 PM, ID: 22925535Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/10/08 02:25 PM, ID: 22926270Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/10/08 02:28 PM, ID: 22926297Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/10/08 03:41 PM, ID: 22926801Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/10/08 07:22 PM, ID: 22927602Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/12/08 04:28 AM, ID: 22938766Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/12/08 07:39 AM, ID: 22940602Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/12/08 07:47 AM, ID: 22940699Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/12/08 01:09 PM, ID: 22944218Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/12/08 01:21 PM, ID: 22944342Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/12/08 01:55 PM, ID: 22944707Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/14/08 08:19 AM, ID: 22960915Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/14/08 11:19 AM, ID: 22962607Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/14/08 12:41 PM, ID: 22963417Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/14/08 12:46 PM, ID: 22963479Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/14/08 01:32 PM, ID: 22963902Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/14/08 01:36 PM, ID: 22963933Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/14/08 08:21 PM, ID: 22965768Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/15/08 10:42 AM, ID: 22968048Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/15/08 01:38 PM, ID: 22968543Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 / EE_QW_2_20070628