Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 PHP If Statments + Links
Index -> Programming, PHP -> PHP Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Tycoon




PostPosted: Mon Mar 27, 2006 7:45 am   Post subject: PHP If Statments + Links

Hello everyone,

I am a website coder but I am still learning PHP and I need to know how to split a php file into sections and have them accessable throught links.

When you click a link, it will load the file (lets call it help.php) and go to the appropriate section the link specified.
Example:
Link 01 = section 1 in help.php
Link 02 = section 2 in help.php
Link 03 = section 3 in help.php

help.php
<?php
// Section 1
blah blah
//section 2
he he he
//section 3
ho ho ha
// if no link clicked, use just found this file
No Input Selected.
?>

Note: I would just create 10 different pages and have them redirect their but I rather have it neatly in one file - for the purpose I am using - otherwise, I would just create 10+ files Smile lol
Sponsor
Sponsor
Sponsor
sponsor
md




PostPosted: Mon Mar 27, 2006 10:30 am   Post subject: (No subject)

Umm... bookmarks? Using bookmarks you can send the user to a specific point on a page... if you're talking about dynamically generating the content of said page depending on what link they click you might want to look into &_GET.
Tycoon




PostPosted: Mon Mar 27, 2006 4:13 pm   Post subject: (No subject)

Cornflake wrote:
Umm... bookmarks? Using bookmarks you can send the user to a specific point on a page... if you're talking about dynamically generating the content of said page depending on what link they click you might want to look into &_GET.


Yeah generating the content, like the file will have all (in this case) interviews and if you click on different links it will load the appropriate interview

so say I click on Tycoon in the navigation list it will go to the interview file and only load Tycoon's interview
md




PostPosted: Mon Mar 27, 2006 5:46 pm   Post subject: (No subject)

Load only that, or load all and jump to that interview? The first can be done with bookamrks, the second would require using $_GET and some php. I'd personally recomend the first if the interviews are static since it'll cut down on server time.
Blade




PostPosted: Wed Mar 29, 2006 2:08 am   Post subject: (No subject)

he's talking about case or switch statements..
it'll go something like this:
php:
<?
  $id = $_GET['id']; //gets the $id from address bar ie: http://www.site.com/index.php?id=go
  if(!isset($id)){ //checks to see if it's set
    $id = "";
  }
  switch($id){  //creates a switch for $id
  default:
  // if $id is blank, this is loaded so if you call index.php with no $id, this is displayed

  break; //stops script
  case "go":
  // if $id=go script jumps here and executes everything up to the next break;

  break;
  } //close the switch
?>
da_foz




PostPosted: Mon Apr 17, 2006 9:15 pm   Post subject: (No subject)

php:

<?
  if(!isset($_GET['id'])) { //checks to see if it's set
    $id = 1; // default value
  } else {
    $id = $_GET['id'];
  }

  switch($id){ 
  case "1":
  include('file_one');
  break;
  case "2":
  include('file_two');
  break;
  case "3":
  include('file_three');
  break;
...
  default:
  break;
  } //close the switch
?>


blade edit: crap, sorry, i clicked the edit button and not quote..
da_foz




PostPosted: Mon Apr 17, 2006 9:17 pm   Post subject: (No subject)

Hmmm, note to self, use 'code' tags and not 'php' tags. I don't see an edit button for my post, am I blind or is it really not there?
[Gandalf]




PostPosted: Mon Apr 17, 2006 10:06 pm   Post subject: (No subject)

da_foz wrote:
Hmmm, note to self, use 'code' tags and not 'php' tags. I don't see an edit button for my post, am I blind or is it really not there?

You didn't really need to post this...
No, there is no edit button in posts in the various help forums, as was decided because of people editing their posts after recieving help.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, PHP -> PHP Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: