newbie PHP help

  • Platinum•
  • Novice
  • Novice
  • User avatar
  • Posts: 25
  • Loc: Australia

Post 3+ Months Ago

ok heres what I want to do ok I'll make it as understandable as I can...

I want a index.php so that when you type in the browser,

http://web here.com/index.php?downloads

It goes to a diffrent layout.

http://web here.com/index.php?affiliates

It changes to a diffrent lay out.

I want it so that The code of Index.php contains a hole page called Downloads and that only shows when ?downloads is typed after index.php e.g. index.php?downloads can any one help me?

I'm kinda very new to PHP... And I'm crappy at it :oops:
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Pretty easy what you want to do.
PHP Code: [ Select ]
 
$page_id = (empty($_GET['pageID'])) ? "" : $_GET['pageID'];
 
switch($page_id){
 
     case "downloads":
 
     //execute page layout code here
 
         break;
 
     case "affiliates":
 
     //execute layout code for affiliates here
 
         break;
 
     default:
 
     //execute home page code layout here
 
}
 
 
  1.  
  2. $page_id = (empty($_GET['pageID'])) ? "" : $_GET['pageID'];
  3.  
  4. switch($page_id){
  5.  
  6.      case "downloads":
  7.  
  8.      //execute page layout code here
  9.  
  10.          break;
  11.  
  12.      case "affiliates":
  13.  
  14.      //execute layout code for affiliates here
  15.  
  16.          break;
  17.  
  18.      default:
  19.  
  20.      //execute home page code layout here
  21.  
  22. }
  23.  
  24.  


and when aclling the pages you will use something like
http://web here.com/index.php?pageID=downloads

Nice and easy
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

rabid, dont that make code look messy and hard to edit?!
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Well it depends how you do it.

Personally, I feel that if you are going to go to a different section of the site then have a different page -> this will allow you to address the special problems each page delivers in a moduler format.
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

:/
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

The way I addressed a similar issue on my site was to have layout.php, which contains two functions:
MakeHeader()
MakeFooter()

And then my actual pages look like this:
PHP Code: [ Select ]
 
<?php
 
include('style/layout.php');
 
$PageTitle="CSS tutorials and CSS Layout Techniques - CaffeineFuelled.net";
 
$PageKeyWords="CSS, Layouts, tutorials";
 
$PageDescription="A site offering detailed tutorials on CSS layout techniques and standards compliance";
 
$ContentTitle="CSS Based Website Design Tutorials";  // <-- the top h1 tag contents, to make it slightly easier.
 
 
 
MakeHeader();
 
?>
 
<p>
 
    stuff
 
</p>
 
<h2>SubHeader</h2>
 
<p>
 
    more stuff
 
</p>
 
<?php MakeFooter(); ?>
  1.  
  2. <?php
  3.  
  4. include('style/layout.php');
  5.  
  6. $PageTitle="CSS tutorials and CSS Layout Techniques - CaffeineFuelled.net";
  7.  
  8. $PageKeyWords="CSS, Layouts, tutorials";
  9.  
  10. $PageDescription="A site offering detailed tutorials on CSS layout techniques and standards compliance";
  11.  
  12. $ContentTitle="CSS Based Website Design Tutorials";  // <-- the top h1 tag contents, to make it slightly easier.
  13.  
  14.  
  15.  
  16. MakeHeader();
  17.  
  18. ?>
  19.  
  20. <p>
  21.  
  22.     stuff
  23.  
  24. </p>
  25.  
  26. <h2>SubHeader</h2>
  27.  
  28. <p>
  29.  
  30.     more stuff
  31.  
  32. </p>
  33.  
  34. <?php MakeFooter(); ?>

Keeps everything neat, I can specify all my title and meta stuff in the page itself, which then gets echo()'d during the makeHeader() function, and each page goes in a separate file, that just has the useful content in it. It makes it really easy to correct my mistakes and do updates and suchlike. Like RD says, keep different pages in different files for ease of use.

It's so my urls are /path/file.php which is much better than having pageId=1, I would only use that if the site was completely database driven.


//edit, no this isn't even close to the same thing now I reread the post :roll: .... But it is still a good idea to keep all of the different page contents separately
  • Platinum•
  • Novice
  • Novice
  • User avatar
  • Posts: 25
  • Loc: Australia

Post 3+ Months Ago

but I want all the page contence in one hole page with that ?function at the end of file.php
  • Liquescence
  • Proficient
  • Proficient
  • User avatar
  • Posts: 353
  • Loc: Queens, NY

Post 3+ Months Ago

Okay, here's one way to do this. Everything that you want to be at the end of the question mark (ie. index.php?page1, index.php?page2, etc) will be saved onto one file (index.php), like this:

PHP Code: [ Select ]
<?php include('header.inc');
 
 
 
if(!$_SERVER['QUERY_STRING']) { ?>
 
 
 
   // Here would be the default stuff, ie. when someone types
 
   // in index.php, with nothing at the end of the address.
 
 
 
<? } elseif ($_SERVER['QUERY_STRING'] == "page1") { ?>
 
 
 
   // Here you type the HTML that you want people to see
 
   // when they type  index.php?page1
 
 
 
<? } elseif ($_SERVER['QUERY_STRING'] == "page2") { ?>
 
 
 
   // Here goes the html if someone types in index.php?page2
 
 
 
   // You can add as many elseifs as you want...
 
 
 
<? } else
 
include ('404.shtml');{ ?>
 
 
 
   // The above part can be used for something like a mispelled
 
   // page or something (ie. index.php?wrongpage).
 
 
 
<? }  include('footer.inc'); ?>
  1. <?php include('header.inc');
  2.  
  3.  
  4.  
  5. if(!$_SERVER['QUERY_STRING']) { ?>
  6.  
  7.  
  8.  
  9.    // Here would be the default stuff, ie. when someone types
  10.  
  11.    // in index.php, with nothing at the end of the address.
  12.  
  13.  
  14.  
  15. <? } elseif ($_SERVER['QUERY_STRING'] == "page1") { ?>
  16.  
  17.  
  18.  
  19.    // Here you type the HTML that you want people to see
  20.  
  21.    // when they type  index.php?page1
  22.  
  23.  
  24.  
  25. <? } elseif ($_SERVER['QUERY_STRING'] == "page2") { ?>
  26.  
  27.  
  28.  
  29.    // Here goes the html if someone types in index.php?page2
  30.  
  31.  
  32.  
  33.    // You can add as many elseifs as you want...
  34.  
  35.  
  36.  
  37. <? } else
  38.  
  39. include ('404.shtml');{ ?>
  40.  
  41.  
  42.  
  43.    // The above part can be used for something like a mispelled
  44.  
  45.    // page or something (ie. index.php?wrongpage).
  46.  
  47.  
  48.  
  49. <? }  include('footer.inc'); ?>


** header/footer includes optional. :)

I used this method for my site for a while.

Post Information

  • Total Posts in this topic: 8 posts
  • Users browsing this forum: No registered users and 85 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.