Good Day, I am trying to concatenate the values that are being fetched through "$_GET" The values like medicine name are being fetched from database dynamically.
while ($row = $result->fetchObject())
{ $display .= "<tr><td>$row->MedName</td>". "<td>$row->MedPrice</td>". "<td>$row->MedStock</td>". "<td>$row->MedDetail</td>". "<td><a href='storepage.php?id=$row->MedName' style='text-decoration: none; color: purple'>Add to cart</a></td> </tr>";}
$display .= "</table>";
echo $display;
$comma_separated = join(",", $array($_GET['id']));
array_push($_SESSION['basket'], $comma_separated );
echo $dis = "<a href='test.php'>go</a>";
The values are being saved in $_SESSION['basket']
<?php
session_start();
if (isset($_SESSION['mail']))
{
$_SESSION['basket'] = array();
}
else
header("location: clientsigninpage.php?msg= Log-in First");
?>
My problem here is that as soon as I press Add to cart multiple times and I go to the test-page it prints only the last value in the next page, it does not concatenate.
<?php
session_start();
if (isset($_SESSION['mail']))
{
$list = $_SESSION['basket'];
}
else
header("location: clientsigninpage.php?msg= Log-in First");
foreach ($list as $value)
{
echo $value;
}
I have seen some solutions but i couldn't get my solution as I want to dynamically get the data and store it. The links are: http://php.net/manual/en/function.array-push.php; https://www.w3schools.com/php/func_array_push.asp; How to add elements to an empty array in PHP?; How to push both value and key into array