SitePoint Sponsor

User Tag List

Results 1 to 14 of 14

Thread: PHP switch code

  1. #1
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP switch code

    I have been trying for about an hour to add this code i got to a php switch can someone please help me add it:

    $membersonlyurl = "<a href="#" onclick="parent.chatframe.document.getElementById('TypicalPlayerApplet').roomID(<?= $qry3[RoomID] ?>); return false;"><?= $qry3[RoomName] ?></a>";
    Animated Chatrooms - www.121chatrooms.net

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    You're going to have to post the switch statement in question if you need it fixing.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The code works if i change the text inside it to test, but it just wont work with what i want to have inside it.
    Animated Chatrooms - www.121chatrooms.net

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,510
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Escape the quotes inside the text.

  5. #5
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    do you mean change it to this:

    $membersonlyurl = <a href="#" onclick="parent.chatframe.document.getElementById('TypicalPlayerApplet').roomI D(<?= $qry3[RoomID] ?>); return false;"><?= $qry3[RoomName] ?></a>;
    Animated Chatrooms - www.121chatrooms.net

  6. #6
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    $sMemberLevel 
    'ADMIN';

    switch (
    $sMemberLevel)
    {
        case 
    'ADMIN':
            
    $sLink sprintf(
                
    '<a href="%s">%s</a>',
                
    'admin.php',
                
    'Admin'
            
    );
        break;

        case 
    'MEMBER':
            
    $sLink sprintf(
                
    '<a href="%s">%s</a>',
                
    'member.php',
                
    'Member'
            
    );
        break;
        
        default:
            
    $sLink sprintf(
                
    '<a href="%s">%s</a>',
                
    'visitor.php',
                
    'Visitor'
            
    );
        break;
    }

    echo 
    $sLink;
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  7. #7
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    Lytham
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $membersonlyurl = "<a href=\"#\" onclick=\"parent.chatframe.document.getElementById('TypicalPlayerApplet').roomI D(<?= $qry3[RoomID] ?>); return false;\"><?= $qry3[RoomName] ?></a>";

  8. #8
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    all working now thank you
    Animated Chatrooms - www.121chatrooms.net

  9. #9
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,510
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Mike4x4s View Post
    do you mean change it to this:

    $membersonlyurl = <a href="#" onclick="parent.chatframe.document.getElementById('TypicalPlayerApplet').roomI D(<?= $qry3[RoomID] ?>); return false;"><?= $qry3[RoomName] ?></a>;

    No.
    Escape the quotes inside the text: " becomes \"

    $membersonlyurl = "<a href=\"#\" onclick=\"parent.chatframe.document.getElementById('TypicalPlayerApplet').roomI D(<?= $qry3[RoomID] ?>); return false;\"><?= $qry3[RoomName] ?>";

  10. #10
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm actually it dosnt appear to do anything when i click the link now, are you sure its corrent?
    Animated Chatrooms - www.121chatrooms.net

  11. #11
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    It's your code, you should know!!!

    I keep telling you, don't blindly follow code provided. Learn from it instead of just copying and pasting. After a couple of years of learning, you should know how to debug things like this.

    Look at the HTML sourcecode to see what the output is, and see what it should be.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  12. #12
    SitePoint Enthusiast LSC-Rob's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, NSW Australia
    Posts
    91
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Should there be a space in 'roomI D(' ??

    $membersonlyurl = "<a href=\"#\" onclick=\"parent.chatframe.document.getElementById('TypicalPlayerApplet').room I D(<?= $qry3[RoomID] ?>); return false;\"><?= $qry3[RoomName] ?>";
    Rob G.
    ShopManager - Sales & Repair Business Management Software

  13. #13
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In the code there is no space but it appears only in the sitepoint forum
    Animated Chatrooms - www.121chatrooms.net

  14. #14
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    fixed, all working had php tags where didnt need to be
    Animated Chatrooms - www.121chatrooms.net


Bookmarks

Posting Permissions

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