2011-11-15 3 views
0

원격 XML 파일을 가져 와서 제품 데이터가있는 테이블을 표시하는 스크립트가 있습니다. 데이터 형식은 다음과 같습니다 MySQL 데이터베이스없이 배열만을 사용하여 결과를 표시하는 방법

ID, name, price, months. 

+++++++++++++++++++ 

1, Name1, $24, 12 

2, Name2, $11, 24 

2, Name2, $10, 36 

3, Name3, $16, 12 

2, Name2, $9, 48 

4, Name4, $26, 12 

+++++++++++++++++++ 

당신이 ID 2 Name2를 참조로

은 동일한 제품이지만, 다른 달과 다른 가격의 선택에.

나는

아무도 나를위한 몇 가지 PHP 함수를 작성 도와 드릴까요 한 번만 동일한 제품 이름을 표시하고 달의 선택과 그것을위한 드롭 다운 메뉴가 있습니다 (그래서 가격이 해당 메뉴의 값으로 이동합니다) 필요 그것? 그것은 MySQL 데이터베이스, 어쩌면 PHP 배열을 사용해서는 안됩니다 ...

대단히 고마워요! 귀하의 관심

++++++++++++++++++++++++++++++++++++

정말 고마워요 , 정말로 이것을 감상! 월)의 투 론강 (Turon에 의해 기능이 해결책으로 보이지만, 내가 그것을 구현하는 문제가 .. 여기 내 실제 코드입니다 :

<? 
try 
{ 
$client = new soapclient("https://api.thesslstore.com/WBService.svc?wsdl", array('trace' => 1,'soap_version' => SOAP_1_1)); 


$parameters = array('objAuth'=>array("ResellerUserName"=>"[email protected]","ResellerPassword"=>"password","PartnerCode"=>000000111)); 

// get the result, a native PHP type, such as an array or string 
$result = $client->GetAllProductPrice($parameters); 

$counter=count($result->GetAllProductPriceResult->AllProductPrice->AllProductPricing); 

for ($i=0; $i<$counter; $i+=1) { 

printf("<tr><td> %s \n", $result->GetAllProductPriceResult->AllProductPrice->AllProductPricing[$i]->NumberOfMonths ."</td>"); 
printf("<td> %s \n", $result->GetAllProductPriceResult->AllProductPrice->AllProductPricing[$i]->Price ."</td>"); 
printf("<td> %s \n", $result->GetAllProductPriceResult->AllProductPrice->AllProductPricing[$i]->ProductCode ."</td>"); 
printf("<td> %s \n", $result->GetAllProductPriceResult->AllProductPrice->AllProductPricing[$i]->ProductName ."</td>"); 

} 
catch (Exception $e) 
{       
printf("Error:sendSms: %s\n",$e->__toString()); 
} 

exit; 
?> 

을 그리고 여기에 라이브 예제 : 당신의 도움에 대한 http://webservice.ge/eus/TestPHPAPIProductDetails.php

감사합니다!

+2

ID의 전체적인 점은 고유하다는 것입니다. 복제했을 때 그 점을 다소 죽였을 것입니다. 절대 일어나서는 안됩니다. –

+0

XML 문서의 예를 들려 줄 수 있습니까? (CSV가 아닌 실제 Dom 트리) – Tomas

답변

0
// prepare $data from your SOAP object 
$result = $client->GetAllProductPrice($parameters); 
$x = $result->GetAllProductPriceResult->AllProductPrice->AllProductPricing; 
$data = array(); 
for ($i=0; $i<count($x); $i++) { 
    $data[] = get_object_vars($x[$i]); 
} 

// transform to format that suits your purpose 
$result = []; 
foreach($data as $item) { 
    $key = $item["name"]; 
    if(!isset($result[$key])) $result[$key] = array(); 
    $result[$key][$item["price"]] = $item["months"]; 
} 

// create your HTML code 
ksort($result); 
foreach($result as $key=>$item) { 
    ksort($item); // optional if you want options sorted asc 
    echo "<select name=\"$key\">"; 
    foreach($item as $value=>$text) echo "<option value=\"$value\">$text</option>"; 
    echo "</select>"; 
} 
+0

내 편집 된 게시물을 참조하십시오. 도와 줘서 고마워. – user1048339

+0

요점은 조금 불분명하기 때문에 나는 그것을 잡았 으면 좋겠다 - 내 업데이트 된 코드를 참조하십시오. 그것은 당신이 필요로하는 정확한 것이 아닐지 모르지만, 당신이 이미 그것을 함께 넣을 수 있다고 믿습니다. 행운을 빕니다. –

+0

다시 한 번 감사드립니다. 불행히도 작동하지 못했습니다. '치명적인 오류 : 형식으로 stdClass 유형의 객체를 배열로 사용할 수 없습니다'라는 메시지가 표시됩니다. $ data [] = get_object_vars ($ x [$ i]); 또한 '구문 분석 오류 : 구문 오류, 예기치 않은'[ '해당 줄 : $ result = []; 하지만 시간과 도움을 주셔서 감사합니다. – user1048339

관련 문제