Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
How to change content in div with PHP includes? Instead of an Iframe.
Old 08-31-2007, 06:07 AM How to change content in div with PHP includes? Instead of an Iframe.
Skilled Talker

Posts: 84
Location: Brussels, Belgium
Trades: 0
Hi,
I want to know wich alternatives there are instead of Iframes?
I want to make something with PHP. Is that possible?

I have a navigation menu, and a small Iframe place for a bit of content...
Now I want to get rid of that Iframe and replace it by a PHP include or sorth of thing...
So the content in that DIV changes into other things by clicking on the links in the other DIV.

Code:
 
<div id="nav">
<a href="" target="fraim">link1</a><br>
<a href="" target="fraim">link2</a><br>
<a href="" target="fraim">link3</a><br>
</div>

<div id="smallcontent">
<iframe src="blanco.html" name="fraim" width="200" height="200"></iframe>
</div>
Any help?
Thanks,
Bulevardi
__________________

Please login or register to view this content. Registration is FREE
Bulevardi is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 08-31-2007, 07:50 AM Re: How to change content in div with PHP includes? Instead of an Iframe.
Skilled Talker

Posts: 62
Name: Tom Wright
Location: Brighton, UK
Trades: 0
I'm assuming that you meant that you want to just use that page as a template for all of the pages that would come into the iframe. In which case I'd do something like this:
PHP Code:
//top of page stuff...

<a href="/?link=1">Link 1</a>
<a href="/?link=2">Link 2</a>
<a href="/?link=3">Link 3</a>

<?php
$linkno 
= (isset($_GET['link'])) ? $_GET['link'] : 0;

include(
'content' $linkno '.htm');
?>

// rest of the page
This will look to see if the user got to the page through one of the links. If they did then it will load the relevant content page (content1.htm, content2.htm...) directly into the document before it is sent to the browser. If they've not it'll load content0.htm.
Hope this helps, Tom
__________________
My site:
Please login or register to view this content. Registration is FREE
tomythius is offline
Reply With Quote
View Public Profile
 
Old 08-31-2007, 07:55 AM Re: How to change content in div with PHP includes? Instead of an Iframe.
Defies a Status

Posts: 3,420
Trades: 0
I'm no expert on iframes or PHP, but here's a post that might help, courtesy of Dansgalaxy:

http://www.webmaster-talk.com/html-f...tml#post448484
CSS4Life is offline
Reply With Quote
View Public Profile
 
Old 08-31-2007, 12:30 PM Re: How to change content in div with PHP includes? Instead of an Iframe.
Skilled Talker

Posts: 84
Location: Brussels, Belgium
Trades: 0
And something like this won't work?
I'm still learning the basics of PHP



Code:
 
<a href="<?php $linkno . '1' ?>" target="content">Link 1</a>
<a href="<?php $linkno . '2' ?>" target="content">Link 2</a>
<a href="<?php $linkno . '3' ?>" target="content">Link 3</a>
 
<div id="smallcontent">
 
 
<?php
include('content' . $linkno . '.htm');
?>
 
</div>
I don't understand that isset and $_GET thing very well...
__________________

Please login or register to view this content. Registration is FREE
Bulevardi is offline
Reply With Quote
View Public Profile
 
Old 08-31-2007, 04:12 PM Re: How to change content in div with PHP includes? Instead of an Iframe.
Extreme Talker

Posts: 182
Trades: 0
if you are wanting to update just that div without refreshing the page, AJAX is what you need. Prototype is a good js framework with easy ajax functions.

If you're wanting to refresh the whole page...your last post is totally off.

Here is some code w/ some comments to try to make things clear for you.

PHP Code:
// switch statement. this takes in the url parameter 'page' and 
// does crap accordingly. You can have as many different cases as you need
// Note: $HTTP_GET_VARS is safer than $_GET
// because it escapes possible malicious code.
switch ( $HTTP_GET_VARS['page'] )
{
case 
"1"// if ?page=1, this sets $page to 'page_1.php'
    
$page 'page_1.php';
    break;
case 
"2":
    
$page 'page_2.php';
    break;
case 
"3":
    
$page 'page_3.php';
    break;
defaut// if ?page doesnt = 1,2, or 3, this sets $page to 'main_page.php'
    
$page 'main_page.php';
}

<
div id="content_area">
   
// include the proper page from your includes directory
   
include ( 'includes/' $page ); 
</
div

something like that should work. you may want to read up on the switch statement: http://php.net/switch
bhgchris is offline
Reply With Quote
View Public Profile
 
Old 08-31-2007, 04:19 PM Re: How to change content in div with PHP includes? Instead of an Iframe.
Extreme Talker

Posts: 182
Trades: 0
I just noticed you asked about isset() and $_GET:

$_GET: a predefined variable http://us3.php.net/manual/en/reserve....variables.get

There are many ways to pass information from one php page to the next. $_GET is one of them. It is simply an array of the url parameters in the query string of the url.

Example:
if your url was http://www.mysite.com/index.php?page=contact

PHP Code:
echo $_GET['contact']; // will output the word 'contact' 
isset ( ): http://php.net/isset
isset() checks to see if a variable is set or not.

Example:
PHP Code:
if ( isset ( $_GET 'page' ] ) )
{
    echo 
"the page parameter is set in the url";
}
else
{
    echo 
"the page parameter is NOT set";
}

isset() 
checks that the variable is setNOT if it is empty or not 
bhgchris is offline
Reply With Quote
View Public Profile
 
Old 09-02-2007, 01:37 PM Re: How to change content in div with PHP includes? Instead of an Iframe.
Skilled Talker

Posts: 84
Location: Brussels, Belgium
Trades: 0
Thanx bhgchris !

But can you get a php function out of a link - like in javascript:

Code:
 
<a href="<?php openpage1() ?>">link</a> 
 
And than the function opens includes, like:
 
<?php
function (openpage1) {
include "page1.php"; 
}
?>
This would be a super solution, but it's not working.


Otherwise, I found something like this somewhere... :


Code:
 
<a href="?load=page1">Go to page 1</a> 
<a href="?load=page2">Go to page 2</a> 
 
<?php 
if($load ==  "page1") { 
include "page1.php"; 
} 
elseif($load ==  "page2") { 
include "page2.php"; 
} 
else{  
include "errors/fout404.php"; 
}  
?>
In this case, do you have to use this isset thing too?
Cause I'm still not getting the isset issue. Is it just to define '$load' ? like in javascript 'var' ?
Code:
 
<?php 
if(!isset($_GET['load'])) {  
$load = "page1";  
}
else {  
$load = $_GET['load'];  
}  
?>

__________________

Please login or register to view this content. Registration is FREE
Bulevardi is offline
Reply With Quote
View Public Profile
 
Old 09-03-2007, 06:41 PM Re: How to change content in div with PHP includes? Instead of an Iframe.
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
First, thanks whym

isset is to check if its set as said before, its used as means of validation.
in my case in the script whym posted. its used because if it isnt set it shows aother page.
so you could have a simple thing like

PHP Code:
$divpage $_GET['div'];
 
$divpage = (isset($_GET['div']))   ?   $_GET['div'] : 'default_div_content.php';
 
echo 
'<div>';
include (
'pages/'.$divpage.'.php');
echo 
'</div>'
before you ask this:
PHP Code:
$divpage = (isset($_GET['div']))   ?   $_GET['div'] : 'default_div_content.php'
would do exactly the same as:
PHP Code:
if(isset($_GET['div']))
{
$divpage $_GET['div'];
}
 
else {
$divpage 'default_div_content.php';

its just another way to do it.

Hope this helps.
If you want more help i can probably help

Talkupation apprieciated
Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 09-04-2007, 12:29 AM Re: How to change content in div with PHP includes? Instead of an Iframe.
metho's Avatar
Ultra Talker

Posts: 481
Location: Gold Coast - Brisbane QLD, Australia
Trades: 0
Don't trust external data.

isset() performs no validation, I would never dump the contents of a GET var stright into a process without validating it first. A switch does; if the incoming data doesn't comform to one of the cases, a default value can be used.

A switch or an array will do the job nicely. For eg.

Typically I use 3 steps to load includes based on a GET var. Step 1, validate the get var, step 2, check that the include exists, step 3, include the corresponding file.

script: includes/inc_functions.php
PHP Code:
//dual purpose: return bool (true/false) GET var is an index of includes array
//                return string of path/filename to include
function includePage($pageName$validKey true) {

    
//add items to include array as required
    //associative index = string preceding extension full-stop
    //value = relative path to include from root
    
$arr_includes['page1'] = 'includes/inc_page1.php';
    
$arr_includes['page2'] = 'includes/inc_page2.php';
    
    if(
$validKey) {
    
        
$returnBool array_key_exists($pageName$arr_includes);
        return 
$returnBool;
    
    } else {
        
        
//grab include path from array and test if it exists
        
$include_path = (@file_exists($arr_includes[$pageName])) ? $arr_includes[$pageName] : false;
        
        return 
$include_path;
    
    }

html: includes/inc_page1.php
Code:
<p>The qwik brown fox jumped over the lazy page one.</p>
html: includes/inc_page2.php
Code:
<p>The qwik brown fox jumped over the lazy page two.</p>
html: includes/inc_page_error.php
Code:
<p style="color: #FF0000">Error: Page does not exist or has been archived.</p>
Tying all files together to toggle the include.

script: content.php
PHP Code:
<?php 

include_once('includes/inc_functions.php');

$thisPage = (!empty($_GET['page'])) ? $_GET['page'] : false;
$validPage false;

//default page to load if GET var is invalid
$includePage 'includes/inc_page_error.php';

//validate GET var for page
if($thisPage) {

    
$validPage includePage($thisPagetrue);
    
}

//if valid page, overwrite default includePage
if($validPage) {
    
    
$includePage includePage($thisPagefalse);
    
}    

?>
<html><head>
<title>Test Includes</title>
</head>

<body>
<div id="content">
<?php include_once($includePage); ?>
</div>
</body></html>
function includePage() performs get var validation, file_exists() validation and if everything validates returns the appropriate include.
__________________
I do
Please login or register to view this content. Registration is FREE
based.
Spend a lot of time in
Please login or register to view this content. Registration is FREE
.
And
Please login or register to view this content. Registration is FREE
chews up the rest.

Last edited by metho; 09-04-2007 at 12:32 AM.. Reason: added a php comment
metho is offline
Reply With Quote
View Public Profile Visit metho's homepage!
 
Old 09-04-2007, 03:32 AM Re: How to change content in div with PHP includes? Instead of an Iframe.
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
when i said validates i ment it validates if it exists, i was using the term loosly.

and i went for the sort and simple way, i assumed he would expand on it himself.
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to How to change content in div with PHP includes? Instead of an Iframe.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31472 seconds with 12 queries