【发布时间】:2020-01-13 13:03:32
【问题描述】:
我有一个创建行程项目。所有可用的目的地都列在我的右侧面板上,可以通过单击按钮来选择。用户选择所需目的地后,它将显示在同一页面的右侧面板上,在该部分中一切正常。我还使用会话成功地将选定的目标值传递到 url,但是当我要在另一个页面上显示它时,我得到的是选定目标的唯一最后一个值。任何人都可以知道任何解决方案或解决方法吗?任何帮助将不胜感激。先感谢您!
下面是我的项目截图和代码供大家参考。
这是我的右侧面板视图,用户可以在其中选择目的地。
这是我选择目的地的代码。
<?php
session_start();
if(!empty($_SESSION['destinationID'])){
$destinationID = $_SESSION['destinationID'];
}
$dropdown_destination = $_GET['dropdown_destination']?:null;
$dropdown_tourdate = $_GET['dropdown_tourdate']?:null;
require_once("dbcontroller.php");
$db_handle = new DBController();
if(!empty($_GET["action"])) {
switch($_GET["action"]) {
case "add":
if(!empty($_POST["quantity"])) {
$productByCode = $db_handle->runQuery("SELECT * FROM tourist_spot WHERE TOURIST_SPOT_ID='" . $_GET["code"] . "'");
$itemArray = array($productByCode[0]["TOURIST_SPOT_ID"]=>array('TOURIST_SPOT'=>$productByCode[0]["TOURIST_SPOT"],
'code'=>$productByCode[0]["TOURIST_SPOT_ID"],
'quantity'=>$_POST["quantity"],
'PRICE_PER_LOC'=>$productByCode[0]["PRICE_PER_LOC"]));
if(!empty($_SESSION["cart_item"])) {
if(in_array($productByCode[0]["TOURIST_SPOT_ID"],array_keys($_SESSION["cart_item"]))) {
foreach($_SESSION["cart_item"] as $k => $v) {
if($productByCode[0]["TOURIST_SPOT_ID"] == $k) {
if(empty($_SESSION["cart_item"][$k]["quantity"])) {
$_SESSION["cart_item"][$k]["quantity"] = 0;
}
$_SESSION["cart_item"][$k]["quantity"] += $_POST["quantity"];
}
}
} else {
$_SESSION["cart_item"] = array_merge($_SESSION["cart_item"],$itemArray);
}
} else {
$_SESSION["cart_item"] = $itemArray;
}
}
break;
case "remove":
if(!empty($_SESSION["cart_item"])) {
foreach($_SESSION["cart_item"] as $k => $v) {
if($_GET["TOURIST_SPOT_ID"] == $k)
unset($_SESSION["cart_item"][$k]);
if(empty($_SESSION["cart_item"]))
unset($_SESSION["cart_item"]);
}
}
break;
case "empty":
unset($_SESSION["cart_item"]);
break;
}
}
?>
如果用户单击添加,选定的目的地将显示在左侧面板上。
这是关于如何将所选目的地显示到左侧面板并将参数传递给 URL 的代码。
<div class="ui teal segment">
<?php
if(isset($_SESSION["cart_item"])){
$total_quantity = 0;
?>
<div class="">
<?php
foreach ($_SESSION["cart_item"] as $item){
?>
<div class="ui clearing segment iti-details">
<div class="ui left floated header">
<h2 class="ui header">
<img class=" large image" src="resources/images/bg6.jpg">
<div class="content">
<div class=""><?php echo $item["TOURIST_SPOT"]; ?>
</div>
</div>
</h2>
</div>
<div class="ui right floated header">
<i class="ellipsis vertical icon iti-mini"></i>
</div>
</div>
<div class="ui divider"></div>
<?php
$total_quantity += $item["quantity"];
?>
<form action ="checkprice.php">
<input type = "text" name = "destinationID" value = "<?php echo $item["code"];?>">
<?php
}
?>
</div>
<?php
} else {
?>
<div class="no-records">Your Tour Destination is Empty</div>
<?php
}
?>
</div>
这是我来自另一个页面的 URL。在此视图中,所选目的地显示在 URL 中,但不在页面中。
【问题讨论】:
-
PHP 会覆盖 GET 同名参数,除非你在名称中使用
[]创建数组 -?foo[]=value1&foo[]=value2&… -
@04FS 谢谢先生的建议。还想问一下我要选择目的地并显示在另一部分而不刷新页面吗?谢谢
标签: javascript php html json ajax