Very noobish question i know, but I haven't found any help on that. Basically I want to have a 3-page website in 1 file (index.php). How do you construct it so you can call each part of the site from the url header by ID number? Do I need MySQL for that ? How do you setup the url and the variables? Thanks :o

    Thanks for the links bud. Now I was looking at your code:

    // index.php //
    if(isset($page))
    {
     switch ($page)
     {
       case "comics":
          include("comics.php");
          break;
        default:
          include("index2.php");
          break;
      }
    }else
      include("index2.php");
    
    // to link to it //
    <a href=index.php?page=comics>comics page</a>

    Can you explain to me what you've done here?
    I assume this is basically the guts of the code that picks up the variables from the url header and spits out the desired page correct?

    Here we have includes, but is there a way to get all the 3 pages into 1 and identify each part by a variable, and then call that part from the url header?

    thanks

      maybe you can drop the includes, and just break the index.php down into sections.. soemthing like this (im not sure how you want it tho)

      <?
      if(isset($page))
      {
       if($page=="01"){
         ?>
         <html code for section 1>
         <a href=?page=02>page 2</a>
         <a href=index.php>index</a>
         <?
        }elseif($page=="02"){
          ?>
         <html code for section 1>
         <a href=?page=01>page 1</a>
         <a href=index.php>index</a>
         <?  
      }elseif($page!="01" && $page!="02"){ // neither 01 or 02 passed -> refresh to index // echo "<META http-equiv=\"Refresh\" content=\"1;URL=index.php\">"; } else // no page var -> so print index part // { ?> <html code for index part> <a href=?page=01>page 1</a> <a href=?page=02>page 2</a> <? } ?>

      you could also do that with the switch($page) thing, and it shouldnt be that bad if they are small pages.. but if they are big pages, the include might work better..

      hope that helped

        With switch($variable) i have to use case right?

        Thanks for the explanations, if I get stock I will post again 🙂

          yeah, something like

          <?
          if(isset($page))
          {
           switch($page)
           { 
             case "01":
             ?>
              <!--sect 01-->
              <a href="?page=02">page 2</a>
              <?
               break; // this is important so it doesnt 'fallthrough' to case 02
          
          case "02":
          ?>
           <!--same thing-->
          <?
          break;
          default: // meaning, neither 01 or 02 //
          ?>
            <!-- refresh tag, or whatever error -->
           <?
            }
          }else{
            // index section here
          }
          

            Awsome, i will put that into use and report back 🙂
            I'm taking C++ course this semester so I hope to learn some PHP as well :>

              Okay I used the example with the SWITCH and the CASE.
              http://nullnetwork.com/php/

              Though when I put http://nullnetwork.com/php/index.php
              it takes me to

              else{
              echo "Binary:<br>
              110 10110111110100100 11110  11001010100
              010 0110 1101 10000 1  1000000100   0011
              10 00000101001001100 1 11110010111111101
              01111110 10 111 00111 01010111101011 000
              10110110011111010000110 1010101 00 101 1
              0101011 1001011110101100001010100111000 
              110010011111100010 01111001010110101 011
              01 101101011001101 10011000 100011001110
              10001011010000000000110111 100101100 1  
              0110 11010101011110 10 1101011001000110 0110 010 010100011 0 11000000001000 110 10 110001110100010010 100110001010101011 1000 00000111101010 010010011 1000101010 11111100001000 100001 10101010110101 001 101110111 010010110110110011000111111011 111000110010100011111100010010011100110 0011010011111110001 100 11 1011011101100 1011000100 0 11100001001100011111111101 1110 00010111011100 011000101 010101100 10011011 00100110 000011110101110100101 1100 11 0000001 110 11110001 00 10 1011 0010 010 011000111 1111 101001101011 1 011 01010100100 10010000100 001010110101 11011 00111 1 11101001 01100011 11101 000100100011110000001100001010010 100010 010001 010101111100110100 00111000 0000 0001 010100 100111010101 000001 1111001 0011011111000 110000 111 0 10011110101 0 100 01100000101000011 111010010110 0011 01001 01 00 1010001000101100 0101100 101<br>"; echo "this is default code muahahaha"; } ?>

              (that's after all the CASES)

              And I want it to be whatever is displayed at default, in this case 01. So if you go to the page http://nullnetwork.com/php/ you will be presented with the code from else {}

                the default in switch isnt actually a default, its more of an 'case else:'.. if that wasnt there, the script would just pause when $page wasnt = to 01,02 .. and that sucks 🙂 so thats why i put in a redirect there (or an error)

                the actual default (meaning nothing passed) is under the else because if there is no $page variable, it isntset -> sending it down there.. BUT if there is a $page variable and it doesnt = 01, or 02 -> it will goto the switch:default part..

                  oh i get it now! thanks

                  Now for the else {} part. Is there a way to display the same code as for default without rewriting the whole content ? Like a goto function. So if i only put /php/ (without index.php=01) it will automatically redirect me to index.php?page=01

                    if you want it to do that, in the else part, put this code in

                    // the else from if(isset($page)) //
                    
                    }else{
                     echo "<META http-equiv=\"Refresh\" content=\"0;URL=index.php?page=01\">";
                    // the 0 = delay, and URL is self-explanitory //
                    }
                    

                    i just figured it would be better if the index page was assumed as 01, imo its weird to open a page & redirect- see how you like it

                      Appreciated.

                      I was putting echo "<META http-equiv=\"Refresh\" content=\"1;URL=index.php?page=01\">"; but it kept refreshing, i guess that "0" meant something 😃. I just wanted to redirect it to 01 so it's easier for me visually (if that made sense haha). Again thanks 🙂
                      I would never figure that out, even with a manual...just too many functions heh

                        a few methods of redirecting:

                        // 1.) echo javascript (or with js function) //
                        echo "<script>location=url;</script>";
                        
                        // 2.) echo meta tag -> obv my fav  cause of the delay //
                        echo "<META http-equiv=\"Refresh\" content=\"1;URL=url\">";
                        
                        // 3.) headers, i hate bc they must go before any output //
                        header("Location:url");
                        

                        theres a ton of things to do, but my fav is metas 🙂

                          Thanks for the tips mate
                          I tried

                          header("Location:url");

                          before but it said that the header was "already sent" 😕
                          Would it be because there was some other code above ?

                            if your code sends some text to the browser to dislpay it sends the headers and they can only be sent once...
                            You can see if the headers have been sent using :
                            boolean headers_sent ( void)

                              NB :

                              having HTML in the code will send the headers example :

                              ...?>
                              <img src="blah.gif">
                              <?...

                              will send the headers too

                              Good luck

                                that's why i was getting it, i was echoing something else hehe
                                😃 thanks

                                  Write a Reply...