require function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

require function

Post by bouncer »

hi,

i have a page and inside that page i have multiple tabs, and inside those tabs i want to add some sort of page that is in another php file, something like this

Code: Select all

<?
if ( tab1 ) {
    require 'dir/include/content.php';
}
?>
and at the same time i want to pass a value to the content.php file in order to show the appropriate content.

if it's possible how can i do that ?

thanks in advance
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

do you want it to repost back to content.php as in content.php?tab=1 or just change when they change the tab, because that would be more of a JavaScript project.
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Post by bouncer »

i just want to open content.php inside another page, e.g. main.php, when i go to tab1

thanks in advance
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Did you even try it yet? Seems to me that this would be something very easy to try.

tab.php

Code: Select all

<?php
$tab = 1;
$value = 'I passed this on to you my friend.';
require_once 'content.php';
?>
content.php

Code: Select all

<?php
if ($tab === 1) {
  echo $value;
} else {
  echo 'Tab was not 1.';
}
?>
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Post by bouncer »

now is working thank you both :wink:
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Post by bouncer »

one more question, is it possible to use something like this but without refresh the main.php ?

Code: Select all

function refresh ( cfg ) {
    size = document.frmContent.elements.length;
    ctent = "";
    for ( i=1; i < size; i++ ) {
        ctent = ctent + document.frmContent.elements[i].value +",";	
    }
	
    ctent = ctent.substr(0,ctent.length-1);

    if ( cfg ) {
        location.href = "content.php?c=<?=$c?>&clc=2&arrPrc="+ctent;
    } else {
        location.href = "content.php?c=<?=$c?>&clc=1&arrPrc="+ctent;
    }
}
this function was the one that i use before i include content.php into main.php, but now i want to refresh only content.php without refreshing main.php, is that possible ?

thanks in advance
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Post by bouncer »

can someone give me ideas to the above post, i think that i have to refresh the included .php in the main.php but i dont have sure.

if someone have ideas please let me know :wink:

thanks in advance
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

Read about AJAX :)
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

XMLHttp tutorial (who's online example) for basic theory and example and possibly Dynamic/Chained Selects using Ajax Prototype/JQuery for another example.

You find there is a lot of information on the web about AJAX. XMLHttp is effectively the core thing you need so the initial tutorial is well worth a read to get the principle understood. (Although not strictly true the label "AJAX" is to me just a marketing tag). It should also be worth noting that not everyone uses javascript, therefore you should build pages with no javascript first. Then add in additional functionality (like AJAX) afterwards so it always works. I personally like the tag "enhanced by javascript".

There are several Javascript libraries out there which can help (prototype and Jquery being two) if you do not want to build your own thing.
Post Reply