2013-02-27 69 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