2013-02-27 43 views
0

我已經成功地用PayPal和我自己的付費按鈕設置了Sandbo。現在,在我的感謝頁面中,用戶在重新定向後,我想將詳細信息打印給用戶。通過PDT,我可以獲得發送的數據,以及我如何使用它來呈現數據。需要PDT提取和呈現數據方面的幫助

我有數據$ keyarray,這是一些我PDT的PHP代碼: 截圖:http://snag.gy/PdsQH.jpg

$firstname = $keyarray['first_name']; 
$lastname = $keyarray['last_name']; 
$itemname = $keyarray['item_name']; 
$amount = $keyarray['payment_gross']; 
$id = $keyarray['item_number']; 

echo ("<div id='welcomeText'>Thank you for your purchase!</div>"); 
echo ("<p><div id='bold'>Payment Details</div></p><br>\n"); 
echo ("<div class='abouttext'>Name: $firstname $lastname</div>\n"); 

$string1 = 'item_number'; 
$string2 = 'item_name'; 
$string3 = 'quantity'; 
$count = count($keyarray); 
for($idx = 1; $idx < $count; $idx ++) { 
if (isset($string2) && 'item_name' != null) 
echo ("<div class='abouttext'>Item name: ".$keyarray[$string2.$idx]."</div>\n"); 
echo ("<div class='abouttext'>Item ID: ".$keyarray[$string1.$idx]."</div>\n"); 
echo ("<div class='abouttext'>Qty: ".$keyarray[$string3.$idx]."</div>\n"); 

} 

的問題是,它循環65次,因爲它是那麼長。我想改變$ count = count($ keyarray);來代替次數item_number在$ keyarray中,類似於 $ count = count($ keyarray ['item_number'); - 那可能嗎?我也可以用10而不是$ count進行硬編碼,並將其循環10次,結果不會那麼糟糕。

+0

其中是'item_number4'和'item_number5'? – SparKot 2013-02-27 15:34:11

+0

他們還沒有使用,但沒有什麼區別。我需要知道如何遍歷發送的transationID($ keyarray),並且每次發生$ id/item_number都會回顯該產品的詳細信息。 – 2013-02-27 15:46:30

+0

現在foreach中的$ id($ keyarray as $ id)就是每個條目的值 – 2013-02-27 15:49:03

回答

1

注意:如果您可以在源處更改$keyarray的內容,則更好。

您可以在循環中創建名稱:

例如,

$string = 'item_name'; 

$arr_val = array(
     'item_name1' => 'Kot1', 
     'item_name2' => 'Kot2', 
     'item_name3' => 'Kot3', 
     'item_name4' => 'Kot4', 
     'item_name5' => 'Kot5' 
     ); 


for($idx =1; $idx < 6; $idx ++) { 
    var_dump($arr_val[$string.$idx]); 
} 

此將輸出:

字符串 'Kot1'(長度= 4)

字符串 'Kot2'(長度= 4)

字符串 'Kot3'(長度= 4)

string'Kot4'(length = 4)

s Tring'Kot5'(長度= 4)

編輯:使用下面的代碼找到$keyarray中的實際項目編號。

$array_keys = array_keys($keyarray); 
$count =0; 
foreach($array_keys as $element) { 
    if (!strncmp('item_number', $element, strlen('item_number'))) 
     $count++; 
} 
+0

哇謝謝!使用此代碼:\t '$ string1 ='item_number'; \t $ string2 ='item_name'; ($ idx = 1; $ idx <6; $ idx ++){ \t echo($ keyarray [$ string2。$ idx]); \t echo($ keyarray [$ string1。$ idx]); }'我同時打印了姓名和身份證。但是現在接下來的問題是我該如何操作它的外觀呢?我嘗試過: 'echo(「

Item ID: ($keyarray[$string1.$idx])
\ n」); '但它不是有效代碼 – 2013-02-27 18:16:12

+0

只是分割字符串:'echo(「

Item ID: (".$keyarray[$string1.$idx].")
\ n」);' – SparKot 2013-02-27 18:26:16

+0

Thx,我解決了它有幾條線和回聲,但你的解決方案看起來好多了... 現在這個輸出:http://snag.gy/PdsQH.jpg 我現在遇到的問題是每次打印整個數組長度。有沒有辦法編輯這個:'$ count = count($ keyarray);'例如'$ count = count($ keyarray [item_number]);'所以我等於不同的item_number,即他們的購物籃中的不同產品65的插圖是所有正在發送的條目。 – 2013-02-27 19:32:05