如果这很简单,我还在学习,很抱歉......我想要实现的是一个在线商店结帐系统(不要担心它不会被使用它只是为了我自己的学习,所以任何草率的代码都不会影响一个可怜的企业主但是任何草率代码的皮卡总是值得赞赏的)。
所以我让客户选择产品,然后将它们存储在数组中并显示在篮子中。然后我想将用户带到结帐页面,以便他们可以单击“订单”,然后将这些项目连同他们的用户名一起更新到数据库中的“订单”表中。
我仍然在处理数组(可能是我处于哪个学习阶段的标识符)所以我不确定当我有几个时如何将这些项目(基本上只是 ISBN 号和价格)从我的购物篮带到结帐页面不同的数组。我要做的是展示我如何创建每个数组以及如何在篮子中显示它,希望这将是您可能需要的一切!非常感谢您的阅读,任何帮助将不胜感激。我希望这个问题也可以帮助处于我这个阶段的其他人。
创建数组=
产品.php
echo "<a href='addtolist.php?bookname=" . $bookname . "&bookauthor=" .
$bookauthor . "&bookpub=" . $bookpub . "&bookprice=" . $bookprice .
"&bookisbn=" . $bookisbn . "'>Add to basket</a>";
添加列表.php
<?php
session_start();
if ( !isset($_SESSION['username']) )
{
header("Location:index.php");
exit();
}
$bookarray = array();
$bookarray['bookname'] = $_GET['bookname'];
$bookarray['bookauthor'] = $_GET['bookauthor'];
$bookarray['bookpub'] = $_GET['bookpub'];
$bookarray['bookisbn'] = $_GET['bookisbn'];
$bookarray['bookprice'] = $_GET['bookprice'];
$found = false;
if (isset($_SESSION['list']))
{
foreach ($_SESSION['list'] as $key => $another)
{
if ($_SESSION['list'][$key]['bookisbn'] == $_GET['bookisbn'])
{
$found = true;
break;
}
}
}
if ($found == false)
{
$_SESSION['list'] [] = $bookarray;
}
header('Location: ' . $_SERVER['HTTP_REFERER']);
exit();
?>
显示列表.php
<?php
if (!isset($_SESSION['list']))
{
echo "No list members selected";
}
else
{
?>
<div id="bket2">
<table>
<tr>
<td class='toprow'>Title</td>
<td class='toprow'>Author</td>
<td class='toprow'>Publisher</td>
<td class='toprow'>ISBN</td>
<td class='toprow'>Price</td>
</tr>
<?php
$totalprice=0;
foreach ($_SESSION['list'] as $key => $another)
{
?>
<tr>
<td><?php echo $_SESSION['list'][$key]['bookname']?></td>
<td><?php echo $_SESSION['list'][$key]['bookauthor']?></td>
<td><?php echo $_SESSION['list'][$key]['bookpub']?></td>
<td><?php echo $_SESSION['list'][$key]['bookisbn']?></td>
<td><?php echo "£".$_SESSION['list'][$key]['bookprice']?></td>
<td><a href="removefromlist.php?bookisbn= <?php echo $_SESSION['list'][$key]['bookisbn']?> &location= <?php echo
$_SERVER['PHP_SELF']?> ">[-]</a></td>
</tr>
<?$totalprice += $_SESSION['list'][$key]['bookprice'];?>
<?php
}
}
?>
</table>
<div><h4>Total Price = £<?echo $totalprice;?></h4></div>
</div>
然后在我的篮子里我放
<?php require "displaylist.php" ?
多谢你们