Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Mar 2009
    Posts
    175
    Thanks
    3
    Thanked 1 Time in 1 Post

    Need help converting membership level number to name

    I'm building a personals site based on the osdate cms and am having some trouble with what should be a simple tweak.

    I've put together a script to pull the membership level using:
    PHP Code:
    <b>Current Membership level:</b>
    </td>
    <td>
    <?php echo $this->_tpl_vars['user']['level']; ?>
    <a href="http://www.yoursite.com/custompaymentpage.php> <u><b>Give a membership upgrade gift to this member.</b></u></a>
    </td>
    </tr>
    This will show as
    "Current Membership Level: (1,2,3, or 4) Give a membership upgrade gift to this member."

    Where 1=Gold 2=Silver 3=Visitor and 4=Free

    How do I get this script to show the Gold, silver, Visitor, or Free instead of 1,2,3, or 4?

    Do I need to set up an array to do this?

    I've tried using variations of:
    PHP Code:
    {if ($level=='1')}
                     <
    B> <font color="gold">Gold</font></B>
                 {/if}

                   {if (
    $level=='2')}
                     <
    B> <font color="silver">Silver</font></B>
                 {/if}

                   {if (
    $level=='3')}
                      <
    font color="gray">Visitor</font>
                 {/if}

                   {if (
    $level=='4')}
                      <
    font color="black">Free user</font>
                 {/if} 
    But I can't seem to get it to take.

    I know this is probably super easy for a lot of you out there so any help would be greatly appreciated.
    Last edited by sfraise; 03-12-2009 at 12:15 AM.

  • #2
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    Try this:

    PHP Code:
    if ($level=='1'){
    echo 
    '<B> <font color="gold">Gold</font></B>';
    }

    else if (
    $level=='2'){
    echo 
    '<B> <font color="silver">Silver</font></B>';
    }

    else if (
    $level=='3'){
    echo 
    '<font color="gray">Visitor</font>';
    }

    else if (
    $level=='4'){
    echo 
    '<font color="black">Free user</font>';
    }

    else{
    echo 
    'Something wrong with user??? No level???? lol';


  • #3
    Regular Coder
    Join Date
    Mar 2009
    Posts
    175
    Thanks
    3
    Thanked 1 Time in 1 Post
    I tried:
    PHP Code:
    <tr class="signup_line_outer evenrow">
            <td width="50%">
                <b>Current Membership level:</b>
            </td>
    <td>
            <?php echo $this->_tpl_vars['user']['level']; 
                  if (
    $level=='1'){
    echo 
    '<B> <font color="gold">Gold</font></B>';
    }

    else if (
    $level=='2'){
    echo 
    '<B> <font color="silver">Silver</font></B>';
    }

    else if (
    $level=='3'){
    echo 
    '<font color="gray">Visitor</font>';
    }

    else if (
    $level=='4'){
    echo 
    '<font color="black">Free user</font>';
    }

    else{
    echo 
    'Something wrong with user??? No level???? lol';
    }  
            </
    td>
        </
    tr?>
    But no luck, it just displays the something wrong after the level number.
    Do I need to set this up in a <?php if (( $this-> string?
    Last edited by sfraise; 03-12-2009 at 01:12 AM.

  • #4
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Try
    PHP Code:
    <tr class="signup_line_outer evenrow">
            <td width="50%">
                <b>Current Membership level:</b>
            </td>
    <td>
            <?php echo $this->_tpl_vars['user']['level']; 
                  if (
    $item.level=='1'){
    echo 
    '<B> <font color="gold">Gold</font></B>';
    }

    else if (
    $level=='2'){
    echo 
    '<B> <font color="silver">Silver</font></B>';
    }

    else if (
    $level=='3'){
    echo 
    '<font color="gray">Visitor</font>';
    }

    else if (
    $level=='4'){
    echo 
    '<font color="black">Free user</font>';
    }

    else{
    echo 
    'Something wrong with user??? No level???? lol';
    }  
    ?>
            </td>
        </tr>

  • #5
    Regular Coder
    Join Date
    Mar 2009
    Posts
    175
    Thanks
    3
    Thanked 1 Time in 1 Post
    This is what i'm using in my actual code, I forgot to place the ?> at the end as I copied it in sections.

    Anyway, still not working. Beats the heck out of me.

    If
    PHP Code:
    <?php echo $this->_tpl_vars['user']['level']; ?>
    works where level is the thing we're using, then why in the world doesn't
    PHP Code:
    <tr class="signup_line_outer evenrow">
            <td width="50%">
                <b>Current Membership level:</b>
            </td>
    <td>
            <?php echo $this->_tpl_vars['user']['level']; 
                  if (
    $level=='1'){
    echo 
    '<B> <font color="gold">Gold</font></B>';
    }

    else if (
    $level=='2'){
    echo 
    '<B> <font color="silver">Silver</font></B>';
    }

    else if (
    $level=='3'){
    echo 
    '<font color="gray">Visitor</font>';
    }

    else if (
    $level=='4'){
    echo 
    '<font color="black">Free user</font>';
    }

    else{
    echo 
    ' error';
    }  
    ?>
            </td>
        </tr>
    work?

    What am I missing here?

    Here's what it shows as it is:
    Current Membership level: 2 error
    The member has a silver membership so the 2 that get's displayed is correct, but it shouldn't display the 2, it should be converted to show as silver.
    I'm guessing I need to set up some kind of <?php if (( $this-> string but I'm not sure exactly how to restructure it.
    Last edited by sfraise; 03-12-2009 at 01:16 AM.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    o.O
    PHP Code:
    <tr class="signup_line_outer evenrow">
            <td width="50%">
                <b>Current Membership level:</b>
            </td>
    <td>
    <?php
    $sColour 
    'red';
    $sType 'Error!';
    switch (
    $this->_tpl_vars['user']['level'])
    {
        case 
    1:
            
    $sColour 'gold';
            
    $sType 'Gold';
            break;
        case 
    2:
            
    $sColour 'silver';
            
    $sType 'Silver';
            break;
        case 
    3:
            
    $sColour 'gray';
            
    $sType 'Visitor';
            break;
        case 
    4:
            
    $sColour 'black';
            
    $sType 'Free';
            break;
    }
    printf("<span style=\"font-color:%s\">%s</span>\n"$sColour$sType);
    ?>
            </td>
        </tr>
    The problem with what you have above is that the $level variable has not been defined.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •