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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    New Coder
    Join Date
    Aug 2004
    Location
    Uppsala, Sweden
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing the code on every page.

    When a user comes to the page they can make a choice 'tween 1 & 2 and each one of them tells the entire site to use one specific code.

    like in page1 I have code 1 and 2. code one will be the one sent to the user if he chosed option 1. the same with page 2.

    the codes in each page are not the same though.

    this is mainly because I want to eliminate the extra files for each alternetive and still have one file for page1, but with the two options.

    hope you understand what I want to do.
    how would I go about doing this?

    cheers!
    -Mattias

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    Hey Mattias,

    The best way to do what you want is using php's switch function. Il give you a simple example...

    PHP Code:
    switch ($option) {
    case 
    1:
       echo 
    "User has selected option 1 - blah blah html code here for option 1";
       break;
    case 
    2:
       echo 
    "User has selected option 2 - blah blah html code here for option 2";
       break;

    To actuall change the option.. put a link/button/image whatever that links to yourpage.php?option=1(or 2) or send it to using a form...

    Make sense?

    Sir P

  • #3
    New Coder
    Join Date
    Aug 2004
    Location
    Uppsala, Sweden
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeah, makes perfect sense

    could I have a text-link that sends it as a form so I don't to use yourpage.php?option=1 ?

    What I thought on my way to work was that you could do something with if and else-statements

    something like this:
    if option=1
    html text 1

    else
    html text 2

    -Mattias

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    Hey..
    yeh you can use else if.. but if you have lots of code in the middle.. it gets very slow.. the switch command is much more reliable

    To use a text link send as html form.. you would need dhtml/javascript for that.. whats wrong with a form button?

    Your not 'THE' --Mattias of tabheaven/db by any chance are you? :P *long shot*

  • #5
    New Coder
    Join Date
    Aug 2004
    Location
    Uppsala, Sweden
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A form button in this case is pretty ugly

    Well, since I don't know what you just said I guess not :P

    So how do I pass the value from the "front" page to the other pages?

    Code:
    <form method="POST" action="???" name="switch">
       <INPUT TYPE="HIDDEN" NAME="option" VALUE="IE">
       <input type="submit" value="IE">
    </form>
    
    <form method="POST" action="???" name="switch">
       <INPUT TYPE="HIDDEN" NAME="option" VALUE="Other">
       <input type="submit" value="Other">
    </form>
    Last edited by Noumenon; 10-06-2004 at 06:26 AM.

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    If you do not want to use a form button you can use a form but have an image instead of a standard button.. or if you want text links.. either use a session or cookie to save the choice?

  • #7
    New Coder
    Join Date
    Aug 2004
    Location
    Uppsala, Sweden
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    mkay.

    wich would be best to use, session or cookie?

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts
    I'd say session... mearly becuase people can disable cookie's

  • #9
    New Coder
    Join Date
    Aug 2004
    Location
    Uppsala, Sweden
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay.

    This is what I have so far, although it doesn't work using top.php?browser=1

    PHP Code:
    <TABLE WIDTH="100%" HEIGHT="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
        <TR>
            <TD ALIGN="center" VALIGN="bottom">
                  <IMG SRC="pics/logo.gif">
            </TD>
        </TR>
        <TR>
            <TD ALIGN="center" VALIGN="middle">
                  <IMG SRC="pics/line.gif" WIDTH="600" HEIGHT="1"><BR>
                <?php
                
    switch ($browser) {
                    case 
    1:
                        echo 
    "<FONT>";
                        echo 
    "    <A HREF=\"#News\" TARGET=\"Contents\" onClick=\"return moveX(0, 'contents')\">NEWS & UPDATES</A>  |  ";
                        echo 
    "    <A HREF=\"#Media\" TARGET=\"Contents\" onClick=\"return moveX(528, 'contents')\">MEDIA</A>  |  ";
                        echo 
    "    <A HREF=\"#Music\" TARGET=\"Contents\" onClick=\"return moveX(1056, 'contents')\">MUSIC</A>  |  ";
                        echo 
    "    <A HREF=\"#Band\" TARGET=\"Contents\" onClick=\"return moveX(1584, 'contents')\">THE BAND</A>  |  ";
                        echo 
    "    <A HREF=\"#Interactive\" TARGET=\"Contents\" onClick=\"return moveX(2112, 'contents')\">INTERACTIVE</A>  |  ";
                        echo 
    "    <A HREF=\"#Miscellaneous\" TARGET=\"Contents\" onClick=\"return moveX(2640, 'contents')\">MISCELLANEOUS</A>";
                        echo 
    "</FONT>";
                    break;
                    case 
    2:
                        echo 
    "<FONT>";
                        echo 
    "    <A HREF=\"contents/news.php\" TARGET=\"contents\">NEWS & UPDATES</A>  |  ";
                        echo 
    "    <A HREF=\"contents/media.php\" TARGET=\"contents\">MEDIA</A>  |  ";
                        echo 
    "    <A HREF=\"contents/music.php\" TARGET=\"contents\">MUSIC</A>  |  ";
                        echo 
    "    <A HREF=\"contents/band.php\" TARGET=\"contents\">THE BAND</A>  |  ";
                        echo 
    "    <A HREF=\"contents/interactive.php\" TARGET=\"contents\">INTERACTIVE</A>  |  ";
                        echo 
    "    <A HREF=\"contents/misc.php\" TARGET=\"contents\">MISCELLANEOUS</A>";
                        echo 
    "</FONT>";
                    break;
                }
                
    ?>
            </TD>
        </TR>
    </TABLE>
    The source I get on the page is this:
    Code:
    <TABLE WIDTH="100%" HEIGHT="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
    	<TR>
    		<TD ALIGN="center" VALIGN="bottom">
    			<IMG SRC="pics/logo.gif">
    		</TD>
    	</TR>
    	<TR>
    		<TD ALIGN="center" VALIGN="middle">
    		<IMG SRC="pics/line.gif" WIDTH="600" HEIGHT="1"><BR>
    
    					</TD>
    	</TR>
    </TABLE>
    Last edited by Noumenon; 10-06-2004 at 02:02 PM.

  • #10
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Change
    PHP Code:
    switch ($browser) { 
    to
    PHP Code:
    switch ($_GET['browser']) { 

  • #11
    New Coder
    Join Date
    Aug 2004
    Location
    Uppsala, Sweden
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just did that, no change at all. None of the case-codes are inserted.

    Not even this simple one works:
    PHP Code:
    <?php
    switch ($_GET['browser']) {
        case 
    1:
            include 
    "scripts/scroll.php";
            break;
    }  
    ?>

  • #12
    New Coder
    Join Date
    Aug 2004
    Location
    Uppsala, Sweden
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hah, it worked when I added \n to the html code inside the php code.

    Now when you click either option on the index.php you get directed to main.php?browser=1 (or 2). There in the menu I have changed the code for option 2, so the links are like this: news.php?browser=1 (or 2)...

    But is there a way to do it so I don't have to write the links with ?browser=1... a way that has already set it and it works globally for the whole site?

  • #13
    New Coder
    Join Date
    Aug 2004
    Location
    Uppsala, Sweden
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Anyone who knows how to set it globally for the whole site?

  • #14
    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
    Sorry, your just looking for an easier way to append the url without having to re-write all of the links with browser=x into them?
    Hmm, you could try using a $_SESSION variable to define the opposite, or perhaps a header may be of use for redirection. If you choose the latter, combined with either a $_SESSION or $_GET, you can probably append the url automatically without it even showing in the browser.

    Correct me if I'm wrong, but say you are at index.php?browser=1. You want it so that the links change into index.php?browser=2?

    BTW, I like your scroll

  • #15
    New Coder
    Join Date
    Aug 2004
    Location
    Uppsala, Sweden
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    "Correct me if I'm wrong, but say you are at index.php?browser=1. You want it so that the links change into index.php?browser=2?"

    Didn't quite understand that one :S
    At the index page you chose to go to either main.php?browser=ie or main.php?browser=other. Each one of them calls up a different code. and each of those two codes gives the same option to other pages. I want to skip the part where I have to write the option for each page that needs it for each case.

    Like this example, how do I get rid of that ?browser=other on the Case other?
    PHP Code:
    <?php
    switch ($_GET['browser']) {
        case 
    'ie':
            echo 
    "<FONT>\n";
            echo 
    "    <A HREF=\"#News\" TARGET=\"Contents\" onClick=\"return moveX(0, 'contents')\">NEWS</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
            echo 
    "    <A HREF=\"#Media\" TARGET=\"Contents\" onClick=\"return moveX(528, 'contents')\">MEDIA</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
            echo 
    "    <A HREF=\"#Music\" TARGET=\"Contents\" onClick=\"return moveX(1056, 'contents')\">MUSIC</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
            echo 
    "    <A HREF=\"#Band\" TARGET=\"Contents\" onClick=\"return moveX(1584, 'contents')\">THE BAND</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
            echo 
    "    <A HREF=\"#Interactive\" TARGET=\"Contents\" onClick=\"return moveX(2112, 'contents')\">INTERACTIVE</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
            echo 
    "    <A HREF=\"#Miscellaneous\" TARGET=\"Contents\" onClick=\"return moveX(2640, 'contents')\">MISCELLANEOUS</A>\n";
            echo 
    "</FONT>";
        break;
        case 
    'other':
            echo 
    "<FONT>\n";
            echo 
    "    <A HREF=\"contents/news.php?browser=other\" TARGET=\"contents\">NEWS</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
            echo 
    "    <A HREF=\"contents/media.php?browser=other\" TARGET=\"contents\">MEDIA</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
            echo 
    "    <A HREF=\"contents/music.php?browser=other\" TARGET=\"contents\">MUSIC</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
            echo 
    "    <A HREF=\"contents/band.php?browser=other\" TARGET=\"contents\">THE BAND</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
            echo 
    "    <A HREF=\"contents/interactive.php?browser=other\" TARGET=\"contents\">INTERACTIVE</A>&nbsp;&nbsp;|&nbsp;&nbsp;\n";
            echo 
    "    <A HREF=\"contents/misc.php?browser=other\" TARGET=\"contents\">MISCELLANEOUS</A>\n";
            echo 
    "</FONT>";
        break;
    }
    ?>
    BTW. Thanx for the comment about the scroll, too bad it doesn't work in firefox :S


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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