您好我正在一个客户可以选择一些项目的页面上工作。当客户点击其中一个选择按钮时,?glasstype
会被设置并保存到$_SESSION['showerdoor']['glasstype']['number']
然后,如果$_SESSION['showerdoor']['glasstype']['number']
为1
,2
,3
,4
或5
,我会检查开关,然后设置$_SESSION['showerdoor']['glasstype']['name']
到产品名称。
但现在我遇到了两个问题:
print_r
时,$_SESSION['showerdoor']['glasstype']['number']
页面只显示$_SESSION['showerdoor']['glasstype']['name']
的第一个字母,所以 B (lank)或 S < / strong>(atijnglas)等等。$_SESSION['showerdoor']['glasstype']['number']
以将类添加到所选按钮。我认为我在交换机上做错了但不知道是什么。有人可以给我一些建议吗?
session_start();
if(isset($_GET['glasstype'])) :
$_SESSION['showerdoor']['glasstype']['number'] = $_GET['glasstype'];
endif;
switch($_SESSION['showerdoor']['glasstype']['number']) {
case '1' :
$_SESSION['showerdoor']['glasstype']['name'] = "Blank";
break;
case '2' :
$_SESSION['showerdoor']['glasstype']['name'] = 'Satijnglas';
break;
case '3' :
$_SESSION['showerdoor']['glasstype']['name'] = 'Brons';
break;
case '4' :
$_SESSION['showerdoor']['glasstype']['name'] = 'Grijs';
break;
case '5' :
$_SESSION['showerdoor']['glasstype']['name'] = 'Crepi';
break;
}
print_r($_SESSION['showerdoor']['glasstype']['number']);
HTML(设置?glasstype
):
<a class="choice_button<?php if($_SESSION['showerdoor']['glasstype']['number'] == 1) echo ' selected'; ?>" href="<?php the_permalink(); ?>?glasstype=1">Select</a>
<a class="choice_button<?php if($_SESSION['showerdoor']['glasstype']['number'] == 2) echo ' selected'; ?>" href="<?php the_permalink(); ?>?glasstype=2">Select</a>
<a class="choice_button<?php if($_SESSION['showerdoor']['glasstype']['number'] == 3) echo ' selected'; ?>" href="<?php the_permalink(); ?>?glasstype=3">Select</a>