这是更新页面,其中显示了客户购物篮内容。购物详情保存在“mcart”表格中。 它由mcartId,mcookieId,mpr,mqty,mpn& des fields。 主要部件号,价格,描述&价格折扣取自表2。 典型的更新页面将是这样的:
p-n price qty remove? qty discounts
s-12 10.25 1 remove Items
b-12 3.64 1 remove Items
'Items' contains discount range which is fetched from another table e.g.
Items:
1-5 ,0%
6-19 ,12%
20-39 ,25%
40-59 ,33%
60-99 ,37%
100-199 ,42%
200-499 ,45%
500-9999 ,48%
这些折扣率是隐藏的,一旦用户点击“商品”以切换隐藏或显示,就会显示这些折扣率。 例如,如果客户购买1-5项价格将是2.50英镑,但是6-9,将eb减少到1.90英镑等等。 折扣范围是隐藏的,理想情况下应该在“项目”下显示它们点击的任何项目。 目前它只显示第一项的折扣,正如我所料,无论我选择哪一项。 如何更改javascript,以便记住我点击了哪个项目并仅显示该项目的折扣百分比? 请帮忙!
<script type="text/javascript">
function toggle(id){
var e=document.getElementById(id);
if (e.style.display == '')
{
e.style.display = 'none';
}
else {
e.style.display = '';
}
}
</script>
<?php
// ====== Connection to database ==============================
include("order/connection.php");
// ============== identify if item has been removed or qty changed=> whats the part number? =========
$id = $_GET[id];
$mqty = $_POST[chmqty];
$mpn = $_POST[mmpn];
// ================If qty has been changed ==============
if (isset($_POST['chmqty']))
{
$stmt = $pd->prepare('SELECT * FROM table2 WHERE
part_number=:part_number' );
$stmt->execute(array(':part_number' => $mpn));
$row = $stmt->fetch(PDO::FETCH_BOTH);
// ====== Get the correct price break =====================
for($in =1 ; $in <= 8; $in++)
{
$bb=$row["price_break".($in)];
$halves =explode("-",$bb);
$firstnumber=$halves[0];
$secondnumber=$halves[1];
If ($mqty >= $firstnumber && $mqty <=
$secondnumber)
{
$price=
number_format($row[("price_each".$in)], 2, ".", ",");
}
}
// ================================
$query = "UPDATE mcart SET mqty='$mqty', mpr='$price'
WHERE mcookieId = :cookie AND mpn= :part";
$stmt3=$pd->prepare($query);
$stmt3->BindValue(':cookie',$_COOKIE[mcartId], PDO::PARAM_STR);
$stmt3->BindValue(':part',$_POST[mmpn], PDO::PARAM_STR);
$stmt3->execute();
}
// =============== If DELETE button has been pressed ======
if (!empty($id))
{
$statement2= 'DELETE FROM mcart WHERE mcookieId=? AND mpn=?';
$stmt1 = $pd->prepare($statement2);
$stmt1->execute(array($_COOKIE[mcartId],$id));
}
// ================= Display customer Shopping Basket ==========
$statement= "SELECT * FROM mcart WHERE mcookieId=:cookie";
$stmt2 = $pd->prepare($statement);
$stmt2->bindParam(':cookie', $_COOKIE[mcartId], PDO::PARAM_STR);
$stmt2->execute();
?>
<Table class="tupdate">
<tr >
<th class="pn"> p-n
</th>
<th class="pr"> price
</th>
<th class="qty"> qty
</th>
<th class="remove"> remove?
</th>
<th class="disc">discounts
</th>
</tr>
<?php
while ($row = $stmt2->fetch(PDO::FETCH_ASSOC))
{
echo "<tr class='basket1'>";
// ================ Show Part Numbers ===============
echo "<td class='basket1'>";
echo $row['mpn'];
echo "</td>";
// ================ Show Proces ===============
echo "<td class='basket1'>";
echo $row['mpr'];
echo "</td>";
echo "<form method='POST' action='".$_SERVER['PHP_SELF']."'>";
// ===== Show Qty already in shopping basket that can be changed,
// =====get qty & partnumber if update is clicked ======
echo "<td class='basket1'>";
echo "<input type='number' size='3' value='".$row['mqty']."'
name='chmqty' class='chmqty'>" ;
echo "<input type='hidden' name='mmpn' value='".$row['mpn']."'>";
echo" <Input type='submit' value='update'>";
echo "</form>";
echo "</td>";
// == An item can be removed from basket, get the part number ===
echo "<td class='basket1'>";
echo "<a href='update1.php?id="
.$row['mpn'].
"'>remove</a>";
echo "</td>";
// ===== Show the price break range and associated discount
percentage from Table2 ====
echo "<td class='basket1'>";
?>
<a href="#" onclick="toggle('objDetails')">Items</a>
<span id="objDetails" style="display:none">
<?php
// ====== calculate how many times in basket and the total
price so far =====
$totq=$row["mqty"];
$totqty=$totqty+$totq;
$totp=$row["mqty"]*$row["mpr"];
$totpr=$totpr+$totp;
// ====== Connect to Table 2, Find the relevant p-n and its
discount percentage and lis it =========
$stmt = $pd->prepare("SELECT * FROM table2 LEFT JOIN mcart ON
table2.part_number = mcart.mpn WHERE table2.part_number
=:part_number");
$stmt->execute(array(':part_number' => $row['mpn']));
$row = $stmt->fetch(PDO::FETCH_BOTH);
$c=$row["price_each1"];// price for single item
for($i = 1; $i <= 8; $i++)
{
$b=$row["price_each".$i];
if ($b !=0.00)
{
$d=(($c-$b)/$c)*100;
$complete=$row[("price_break".$i)]. " ," .round($d)."%";
echo"</br>";
echo $complete;
echo"</br>";
}
}
echo "</span>";
echo "</td>";
//}
}
?>
</tr>
<table >
<tr >
<!-- <td ><?php //echo "Total purchases: ".$total."for part
number".$_POST["mpn"];?> </td> -->
<th class="basket2"> </th>
<th class="basket1"><?php echo "Total of £".$totpr;?> </th>
<th colspan="2" class="basket2"><?php echo "for ".$totqty." items";?>
</th>
<th class="basket3"> <img src="/stampede/images/scart.jpg"
alt="Shopping Cart" width="20"> </th>
</tr>
</table>
<?php
echo "</br>";
echo "</br>";
include ("order/options1.php");
?>
答案 0 :(得分:0)
解决。您必须通过URL字符串将变量传递到新页面。 我使用了以下示例:
INSIDE&#34; page1.php&#34;或&#34; page1.html&#34;
// Send the variables myNumber=1 and myFruit="orange" to the new PHP page...
<a href="page2c.php?myNumber=1&myFruit=orange">Send variables via URL!</a>
INSIDE&#34; page2c.php&#34;
<?php
// Retrieve the URL variables (using PHP).
$num = $_GET['myNumber'];
$fruit = $_GET['myFruit'];
echo "Number: ".$num." Fruit: ".$fruit;
?>