美好的一天, 我试图连接通过" $ _ GET"提取的值。医学名称等值正在从数据库中动态获取。
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>";
这些值保存在$ _SESSION [&#39; basket&#39;]
中<?php
session_start();
if (isset($_SESSION['mail']))
{
$_SESSION['basket'] = array();
}
else
header("location: clientsigninpage.php?msg= Log-in First");
?>
我的问题是,只要我多次按下添加到购物车并进入测试页面,它就只打印下一页中的最后一个值,它不会连接。
<?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;
}
我已经看到了一些解决方案,但我无法获得我的解决方案,因为我想动态获取数据并存储它。链接是: 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