Web Design Forum  
 
Go Back   Web Design Forum > Web Software > Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-12-2009, 07:13 AM   #1
Silver Member
 
AusQB's Avatar
 
Join Date: Jul 2008
Location: Perth, Australia
Posts: 167
Send a message via AIM to AusQB Send a message via MSN to AusQB Send a message via Skype™ to AusQB
Default Change pages using PHP

First of all, I'm sorry for cluttering up the forums with all these similar threads, but I keep running into new snags.


What I have here is a main <div> with nav buttons above. When I click the buttons (<td> with onclick function), I want to include() the respective php file into that div.

I've tried all sorts of scripting, but I can't find a solution. I figured the only way to change the contents of the div is to have a function (called from the nav button) that passes a keyword into a switch that will determine the code to write, which I would then insert into the div using the innerHTML attribute.

The problem is that the php statements are parsed before the script is run, so the file data is written out onto the page source. However, it's not even writing that to the div.


I'm sure that might be quite confusing, so please ask for clarification where necessary.

Last edited by AusQB; 03-12-2009 at 09:54 AM.
AusQB is offline   Reply With Quote


Old 03-12-2009, 09:27 AM   #2
adx
Silver Member
 
Join Date: Nov 2008
Location: Minnesota
Posts: 224
Default

Code:
<?php
if (isset($_REQUEST['tab'])) {
$tab = $_REQUEST['tab'];} 
else {$tab = 1;}
?>
<!DOCTYPE...
Code:
<?php
  switch ($tab) {
  case 1:
 ?>
 
   <div id="navbar">   
    <b>Tab 1</b>
    <a href="index.php?tab=2">Tab 2</a>
    <a href="index.php?tab=3">Tab 3</a>
   </div>
   <?php include("page1.php"); ?>
   
 <?php
  break;
  case 2:
 ?>   
 
   <div id="navbar">
    <a href="index.php?tab=1">Tab 1</a>
    <b>Tab 2</b>
    <a href="index.php?tab=3">Tab 3</a>
   </div>
   <?php include("page2.php"); ?>
   
 <?php
  break;
  case 3:     
 ?>
 
   <div id="navbar">
    <a href="index.php?tab=1">Tab 1</a>
    <a href="index.php?tab=2">Tab 2</a>
    <b>Tab 3</b>
   </div>
   <?php include("page3.php"); ?>
 
 <?php
  break;}
 ?>
I think that should do the trick. You can optionally cut out the actual navigation as it's only there so you can highlight the current tab.
__________________
http://www.htmlswag.com
adx is offline   Reply With Quote
Old 03-12-2009, 09:47 AM   #3
Silver Member
 
AusQB's Avatar
 
Join Date: Jul 2008
Location: Perth, Australia
Posts: 167
Send a message via AIM to AusQB Send a message via MSN to AusQB Send a message via Skype™ to AusQB
Default

Thanks, I'll try that.

Just for clarification, is the second batch of code meant to encapsulate the nav bar and the main div area?

Also, why is the first batch of code before the document declaration?


EDIT: That's exactly what I was looking for, thanks. One thing though, how can I change what is initially displayed?

I actually don't need it for changing pages now, but rather for navigating to different levels of a single page. So once I click on one of the links in the "navbar", I want the content of the div to be replaced.

Last edited by AusQB; 03-12-2009 at 10:16 AM.
AusQB is offline   Reply With Quote
Old 03-12-2009, 03:37 PM   #4
adx
Silver Member
 
Join Date: Nov 2008
Location: Minnesota
Posts: 224
Default

Quote:
Originally Posted by AusQB View Post
I actually don't need it for changing pages now, but rather for navigating to different levels of a single page. So once I click on one of the links in the "navbar", I want the content of the div to be replaced.
You can include whatever you want, or simply write the code right in there. It won't change the page it'll just do a refresh and change the contents accordingly. If the code is on the same page, the page will be the same.
i.e. you can have three divs that are essentially the same and it'll swap between them just as you wanted.

Also it doesn't really matter what you put inside the code but anything outside will remain the same.

Code:
<div id="navbar">   
<a href="index.php?tab=1">Tab 2</a>
<a href="index.php?tab=2">Tab 2</a>
<a href="index.php?tab=3">Tab 3</a>
</div>

<?php
  switch ($tab) {
  case 1:
 ?>
   
  <div>something</div>
   
 <?php
  break;
 ...
__________________
http://www.htmlswag.com
adx is offline   Reply With Quote
Old 03-12-2009, 03:43 PM   #5
Silver Member
 
AusQB's Avatar
 
Join Date: Jul 2008
Location: Perth, Australia
Posts: 167
Send a message via AIM to AusQB Send a message via MSN to AusQB Send a message via Skype™ to AusQB
Default

Ah I understand now, thanks. I was just trying to get my head around the tab variable.
AusQB is offline   Reply With Quote


Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 04:18 AM.


Camera Forum - Computer Forum - Web Design Forum

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.