I have a create itinerary project. All the available destination is listed on my right panel and can be selected by button click. After the user select the desire destination/s it will be displayed on my right panel in the same page, in that part all is working great. I have also successfully pass the selected destination value into the url using session but when I am about to display it on another page what I'm getting is the only last value of selected destination. Can anyone know any solution or work around? Any help would be very much appreciated. Thank you in advance!
Below is the screenshot of my project and codes for your reference.
This is my right panel view where user can select a destination/s.
This is my codes for selecting a destination/s.
<?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;
}
}
?>
If user click add the selected destination will be displayed on the left panel.
This is my code on how I display the selected destination to left panel and passing the parameters to 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>
And this is my URL from another page. In this view the selected destination/s is displayed in URL but not in page.



[]in the name to create an array -?foo[]=value1&foo[]=value2&…