Find us elsewhere
Join Now Member Login

PHP Help

 
New Topic
Post Reply
Follow Topic
Page of 1
  • Author
  • Message
 
CommanderK

posts: 19

Nov 02, 2006 3:34 PM ET    Quote  Report Abuse
Points: 0   Vote
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?
asykes

posts: 44

Nov 03, 2006 7:53 AM ET    Quote  Report Abuse
Points: 0   Vote
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
RichardBuggy

posts: 76

Nov 05, 2006 2:32 AM ET    Quote  Report Abuse
Points: 0   Vote
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/
CommanderK

posts: 19

Nov 08, 2006 5:04 PM ET    Quote  Report Abuse
Points: 0   Vote
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?
RichardBuggy

posts: 76

Nov 08, 2006 6:27 PM ET    Quote  Report Abuse
Points: 0   Vote
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/
CommanderK

posts: 19

Nov 11, 2006 6:35 PM ET    Quote  Report Abuse
Points: 0   Vote
Sorry, I should have been more specific.  I meant in the actual code snippet.
RichardBuggy

posts: 76

Nov 13, 2006 5:21 AM ET    Quote  Report Abuse
Points: 0   Vote
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/
CommanderK

posts: 19

Nov 13, 2006 9:58 AM ET    Quote  Report Abuse
Points: 0   Vote
Thanks for all your help Rich.  You too, asykes.
CommanderK2006-11-13 9:59:45
zohahunt77

posts: 12

Feb 14, 2012 3:54 AM ET    Quote  Report Abuse
Points: 0   Vote

 

I came to know about php development softwares which are roaming in the IT industry. I heard about php have more scope in the future because of its security features and ease to apply features.  I also want to learn this php scripting language for my web site developing skills. Can you suggest me from where I should start learning scripting language?

Delta Scripts

 

 

jamescarter1

posts: 4

Apr 13, 2013 8:02 AM ET    Quote  Report Abuse
Points: 0   Vote

Hey, PHP is a well known programming language. It is widely used in web designing because it is an open source programming language so you can use it on other platform. As per the PHP concern i would like to say w3schools is the best website to learn PHP because it is provide great tutorial about PHP that must be very useful for you.



-------------------------

Effective Solutions From Web Development Company | Ecommerce Development Company
Page of 1
Post Reply
 
.
Advertisement

Keep the Community Clean!

  • StartupNation forums should be used as a platform to learn, educate others, share stories, tips & tricks and to provide constructive feedback.
  • Please do not use the Forums for advertising & blatant self-promotion.
  • Please be respectful to other members and refrain from personal attacks and vulgar language.
  • StartupNation reserves the right to delete any message, reply, and/or member who violates our terms of use.
Read full terms of use
Advertisement
Advertisement
Advertisement
Advertisement