0

我在 Authorize.net 网关上工作我需要为逐项账单创建下面的数组

$sql= "select *  from shop where cusid = '1'";
 $sqlexc= mysql_query($sql) or die(mysql_error());

$line_items = array();
while ($title = mysql_fetch_array($sqlexc)) {
    $line_items[] = ('Coupon',' $title[6]', '1', '0.99', 'Y');
}

如何创建以下类型的数组

/*    $line_items = array(
    "Coupon1','description','2','10.99','Y'",
    "Coupon2','description','2','10.99','Y'",
    "Coupon3','description','2','10.99','Y'",);*/
4

2 回答 2

0
$line_items = array();
while ($title = mysql_fetch_array($sqlexc)) {
    $line_items[] = $title;
}
foreach ($line_items as $row){
    echo $row[0]." ".$row[1]." ".$row[2]." ".$row[3]."<br>";
}
于 2012-06-30T04:03:06.327 回答
0

呃..如果你想让它完全一样......

$i=0;
$line_items = array();   
while ($title = mysql_fetch_array($sqlexc)) {
    $line_items[] = "Coupon" . ++$i . "', '" . $title[6] . "', '2', '10.99', 'Y'";
}

但是我会在 mysql_fetch_array 上使用 mysql_fetch_assoc (实际上我会切换到 PDO,因为不推荐使用 mysql)

于 2012-06-30T02:50:07.803 回答