我正在使用php,我有一个产品列表页面,该页面从数据库中获取产品并将其显示给用户。然后,用户选择数量。
问题是我不知道如何在同一页面上显示总价。下一页是计算总价的页面。
有人可以帮助我吗?
我面临的主要问题是,当我更改数量时,它正在重置页面,因此数量变为0。由于需要在另一个页面中进行计算,因此我需要过帐。
include 'Accessories.php';
include_once 'Database.php';
session_start();
$db = new Accessories();
$accessories = $db->getAllAccessories();
echo 'second time';
echo '<br>';
echo '<br>';
echo '<br>';
echo '<form action=" '?> <?php $_SERVER['PHP_SELF']?> <?php echo'" method="post">';
echo '<div class="row"><div class="col-md-1"></div><div class="col-md-10"><input type="submit" name="submited" value="Procced" class="btn btn-block btn-primary"></div></div>';
echo '<div class="container">';
foreach ($accessories as $ac) {
echo
'<div class = "form-group">
<label for="qty_list[' . $ac->taskID . "-" . $ac->taskID . ']">'.$ac->taskName . " " . " " . $ac->description . " " . $ac->price . " BHD".'</label>';
echo '
<input id="" type="number" min="0" onchange="this.form.submit()" class="form-control" name="qty_list[' . $ac->taskID . "-" . $ac->taskID . ']" value="' ?> <?php $_POST['qty_list'] ?> <?php echo'" placeholder="">';
echo'</div>';
echo'<br>';
}
'</div>
</div>
</div>';
echo '</form>';
<?php
session_start();
include_once 'Database.php';
include 'Ac_car_res.php';
include 'Accessories.php';
include 'Reservation.php';
$reserved = false;
//$dateFrom = $_SESSION['dateFrom'];
//$dateTo = $_SESSION['dateTo'];
//echo $dateFrom;
foreach ($_POST['qty_list'] as $key => $qty) {
$r = 102;
//$_SESSION['resId'] = $r;
$qty;
$acAdd = new Ac_car_res();
// session_start();
$resId = $r;
$index = strrpos($key, "-");
$sCarId = substr($key, $index + 1);
$acId = substr($key, 0, $index);
$acAdd->initWith($acId, $resId, $sCarId, $qty);
$acAdd->addAcCarRes();
}
$db = Database::getInstance();
$access = new Accessories();
$res1 = new Reservation();
//echo $Id;
echo "<br>";
$r = 102;
$sql = "select * from ac_car_res where resId=" . $r;
$a = $db->multiFetch($sql);
foreach ($a as $m) {
$access->initWithAcId($m->acId);
$res1->initWithResId($m->resId);
echo "accessories" . $access->getPrice() . "qty" . $m->qty;
echo "<br>";
$totalPriceForRes = ($res1->getTotalPrice() + $access->getPrice() * $m->qty);
$res1->setTotalPrice($totalPriceForRes);
echo $res1->getTotalPrice();
echo "<br>";
$res1->updateReservation();
}
?>
<?php
session_start();
include_once 'Database.php';
include 'Ac_car_res.php';
include 'Accessories.php';
include 'Reservation.php';
$reserved = false;
//$dateFrom = $_SESSION['dateFrom'];
//$dateTo = $_SESSION['dateTo'];
//echo $dateFrom;
foreach ($_POST['qty_list'] as $key => $qty) {
$r = 102;
//$_SESSION['resId'] = $r;
$qty;
$acAdd = new Ac_car_res();
// session_start();
$resId = $r;
$index = strrpos($key, "-");
$sCarId = substr($key, $index + 1);
$acId = substr($key, 0, $index);
$acAdd->initWith($acId, $resId, $sCarId, $qty);
$acAdd->addAcCarRes();
}
$db = Database::getInstance();
$access = new Accessories();
$res1 = new Reservation();
//echo $Id;
echo "<br>";
$r = 102;
$sql = "select * from ac_car_res where resId=" . $r;
$a = $db->multiFetch($sql);
foreach ($a as $m) {
$access->initWithAcId($m->acId);
$res1->initWithResId($m->resId);
echo "accessories" . $access->getPrice() . "qty" . $m->qty;
echo "<br>";
$totalPriceForRes = ($res1->getTotalPrice() + $access->getPrice() * $m->qty);
$res1->setTotalPrice($totalPriceForRes);
echo $res1->getTotalPrice();
echo "<br>";
$res1->updateReservation();
}
?>