dsrbb20862 2013-08-27 20:22
浏览 19

将while循环结果赋给数组值

In switching from authorize.net's SIM method over to AIM method of handling credit card transactions the way a LINE-ITEM is sent to the processor is different. In the (SIM) version, I could send line items by looping through the results and echoing the hidden INPUT field and its values with appropriate separators like this:

$qw = mysqli_query($con,"SELECT * FROM XCart WHERE Buyer_ID='xyz' LIMIT 30");
$ctr=0;
while($list = mysqli_fetch_array($qw))
{
    ++$ctr; 
echo "<input type='hidden' name=\"x_line_item\" value=\"".$list['Item_Number']."<|>".substr($list['Item_Title'], 0, 30)."<|><|>".$list['Item_Qty']."<|>".$list['Item_Price']."<|>Y\">
";
}

But now, under the AIM method, the line items are assigned to an ARRAY, I am still in the infancy stages of PHP, but when I try to place a WHILE LOOP inside of the array similar to the above method, it gives me errors:

$line_items = array( WHILE LOOP INSIDE HERE);

The output of the AIM method should output as shown below, but I'm not sure how to loop through the results in a manner that gives me this output below. I'm missing something and/or doing it wrong, but any help would be appreciated.

$line_items = array(
    "item1<|>golf balls<|><|>2<|>18.95<|>Y",
    "item2<|>golf bag<|>Wilson golf carry bag, red<|>1<|>39.99<|>Y",
    "item3<|>book<|>Golf for Dummies<|>1<|>21.99<|>Y"
);
  • 写回答

1条回答 默认 最新

  • drd99007 2013-08-27 20:25
    关注
    $qw = mysqli_query($con,"SELECT * FROM XCart WHERE Buyer_ID='xyz' LIMIT 30");
    $ctr=0;
    $line_items = array();
    while($list = mysqli_fetch_array($qw))
    {
    $line_items[] = $list['Item_Number']."<|>".substr($list['Item_Title']."<|>".$list['Item_Qty']."<|>".$list['Item_Price']."<|>";
    }
    

    something like this?

    Be carefully, honestly you shouldn't be messing with payment system if you don't know anythign about PHP.....to learn more learn more about php arrays @ http://php.net/array

    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探