如何在会话中获得特定的按钮链接

时间:2015-12-03 17:53:40

标签: php jquery session foreach

通过使用foreach循环,我得到了我需要的输出。 在这种情况下,通过使用foreach循环我将获取具有名称,图像,价格和按钮的产品,每个按钮具有该特定产品链接,当我点击按钮时它将重定向到具有按钮链接的另一页面,因为在其他页面中我应该使用按钮链接。 在我的情况下因为foreach循环,当我点击按钮我将获得按钮链接并存储在会话中可验证但是当这个可用的将在另一个页面中使用它显示最后的产品按钮URL。所以,我的查询是当我点击foreach循环中的按钮时如何获取按钮的特定产品链接,并且该链接将存储在会话中,这是因为我们将在任何使用会话的页面中使用此链接。 / p>

1 个答案:

答案 0 :(得分:0)

如果我理解你的按钮存储了循环中的最后一个id,那么一个解决方案可以像这样

foreach($your_array as $element){
// here maybe you have some table to present data or something
// then print all element fields like you do like echo $element['price']...
// so what you can do is in every loop open up form and close it like this
?>
<form action="another_page.php">
    <input type="hidden" name="id" value="<?php echo $element['id']; ?>">
    //Here you print other input fields
    <input type="submit" name="submit" value="Select this">
</form>
<?php
}

所以在another_page.php上检查是否设置了帖子值,只是将id或其他数据放入会话

相关问题