带开关的Strange SESSION输出

时间:2014-01-06 10:44:52

标签: php multidimensional-array switch-statement session-variables

您好我正在一个客户可以选择一些项目的页面上工作。当客户点击其中一个选择按钮时,?glasstype会被设置并保存到$_SESSION['showerdoor']['glasstype']['number']

然后,如果$_SESSION['showerdoor']['glasstype']['number']12345,我会检查开关,然后设置$_SESSION['showerdoor']['glasstype']['name']到产品名称。

但现在我遇到了两个问题:

  1. 当我print_r时,$_SESSION['showerdoor']['glasstype']['number']页面只显示$_SESSION['showerdoor']['glasstype']['name']的第一个字母,所以 B (lank)或 S < / strong>(atijnglas)等等。
  2. 现在我无法再检查$_SESSION['showerdoor']['glasstype']['number']以将类添加到所选按钮。
  3. 我认为我在交换机上做错了但不知道是什么。有人可以给我一些建议吗?

    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>
    

0 个答案:

没有答案