刷新页面后最后选择的选项 [英] last selected option after refresh the page
问题描述
这是我的链接
http://www.developer.nextgenexperts.in/astika/products_.php
当页面打开时,默认货币在顶部下拉列表中显示INR,如果我选择下拉列表,则我还将获得GBP,而当我们选择GBP时,价格将转换为GBP,但是当我选择GBP时将刷新页面,然后页面为INR,但是我要选择最后一个选项,所以它将如何可能,请帮助我...
When page will open then default currency is showing INR in top dropdown, and if i will select dropdown then i will also get GBP, and when we select GBP, then the price will convert in GBP, But after selecting GBP when i will refresh the page then page is INR, but I want to it last selected option, so how it will possible, pls help me...
推荐答案
只需使用$_SESSION['convert']
:
第一次打开页面时,将检查会话是否存在:
The first time you open the page you will check if session exists:
session_start();
$convert = isset($_SESSION['convert'])?$_SESSION['convert']:"INR";
因此,当您将下拉菜单写为:
So, when you will write your dropdown like:
<form>
<select>
<option value="INR" <?php echo $convert=='INR'?'selected':''?>>INR</option>
<option value="GBP" <?php echo $convert=='GBP'?'selected':''?>>GBP</option>
</select>
</form>
然后在表单提交中,您将选择实际的转换并将其保存在会话中
then on form submit you will take the actual convert selected and save it in session:
session_start();
$convert = $_POST['convert'];
$_SESSION['convert] = $convert;
这篇关于刷新页面后最后选择的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!