簡體   English   中英

如何在PHP的會話數組中存儲屬於變量的金額

[英]How can I store an amount to the belonging variable into a session array in PHP

我得到了一個會話數組,該會話數組將產品存儲在一個數組中,現在我打印出一個表格,其中包含會話數組中的所有產品,以選擇每個產品的數量。 如何在會話中將金額存儲為所有值(produktid)?

if (empty($_SESSION["einkauf"])) {
$_SESSION["einkauf"] = array();
}
array_push($_SESSION["einkauf"], $_GET['id']);

這就是我聲明和填充ID的會話數組的方式:

while ($row = $result->fetch_object()) {
echo "<form method='POST' action='kasse.php'>";
echo "<tr><td>" . $row->Autorname . "</td>";
echo "<td>" . $row->Produkttitel . "</td>";
echo "<td><input type='number' name='anzahl' min='0' max= '10'></input>
</td>";
echo "</tr>";
}

這就是我的產品和選擇金額的選項的打印方式。 因此,我可以輸入一定數量的表格,但是現在如何打印金額到哪一行(哪種產品)?

將數量和product_id放在同一數組中。 最有可能的金額將作為$ _POST標頭傳遞,但如果您想要的話,則不使用$ _GET。

<?php
if (empty($_SESSION["einkauf"])) {
$_SESSION["einkauf"] = array();
}
array_push($_SESSION["einkauf"], array($_GET['id'], $_POST['amount']));

print_r($_SESSION["einkauf"]);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM