Nov. 02 2006 at 4:34 PM
CommanderK Posted by: CommanderK
This is to all you programmers out there.  As a web designer, I am mainly working in HTML and CSS, but I am wanting to "broaden my horizons."  I started messing around with PHP include scripts, i.e.

                   <?php
                           if($_GET['page'] == "1")
                            {
                                include("pages/1.html");
                            }
                      ?>

On some sites, there will be "subsections" like "index.php?page=1&sub=2".  How do you do that?  Can someone give me the code snippet for that?
Commander K | The Creative Liberties Network
Nov. 03 2006 at 8:53 AM
No Photo Posted by: asykes
page=1 is a request parameter where "page" is the parameter name and "1" is the value.

You should be able to find lots of examples on google by searching for something like "php dealing with request parameters"
Read About Double Entry Accounting & The Accounting Equation
Nov. 05 2006 at 2:32 AM
No Photo Posted by: RichardBuggy
Hi CommanderK,

The following will include pages/XXX.html if you specify page=XXX or pages/XXX_YYY.html if you specify page=XXX and sub=YYY.

<?php
  if (isset($_GET['page']))
  {
    $page = intval($_GET['page']);
    if (isset($_GET['sub']))
    {
      $sub = intval($_GET['sub']);

      include('pages/' . $page . '_' . $sub . '.html');
    }
    else
      include('pages/' . $page . '.html);
  }

Blog - http://www.buggy.id.au/
Nov. 08 2006 at 5:04 PM
CommanderK Posted by: CommanderK
Richard,
Could you be more specific as where to put the names of the files, i.e. XXX.html, XXX_YYY.html, and the "names, " i.e. page=XXX, sub=YYY?
Commander K | The Creative Liberties Network
Nov. 08 2006 at 6:27 PM
No Photo Posted by: RichardBuggy
Pick a directory and create a file called index.php with my code in it. In the directory with the index.php file create a subdirectory called pages. Now in pages start creating files XXX.html or XXX_YYY.html (XXX and YYY need to be numbers). You may have something like:

www
   index.php
   pages
      1.html
      2.html
      2_1.html
      3_1.html
      3_2.html

Suppose www is the root directory for your web server. You can now use URL's like
http://myserver.com/index.php?page=1
http://myserver.com/index.php?page=2
http://myserver.com/index.php?page=2&sub=1
http://myserver.com/index.php?page=3&sub=1
http://myserver.com/index.php?page=3&sub=2

Of course people could access your files directly using
http://myserver.com/pages/1.html
http://myserver.com/pages/2.html
http://myserver.com/pages/2_1.html
http://myserver.com/pages/3_1.html
http://myserver.com/pages/3_2.html

This can be fixed by moving the pages directory outside of the websites root directory and using the full path to the directory in the include statements.
Blog - http://www.buggy.id.au/
Nov. 11 2006 at 6:35 PM
CommanderK Posted by: CommanderK
Sorry, I should have been more specific.  I meant in the actual code snippet. Commander K | The Creative Liberties Network
Nov. 13 2006 at 5:21 AM
No Photo Posted by: RichardBuggy
Hi CommanderK

You don't need to hard code page numbers into what I gave you. If you're going to use this in production then I'd recommend three simple changes:

1. Test to see the file exists before including it
2. Exit after including the file
3. Display a page not found message if the bottom is reached.

    Rich

Blog - http://www.buggy.id.au/
Nov. 13 2006 at 9:58 AM
CommanderK Posted by: CommanderK
Thanks for all your help Rich.  You too, asykes.


Edited by: CommanderK - Nov. 13 2006 at 9:59 AM
Commander K | The Creative Liberties Network


To post a reply, please login or join StartupNation