Page 1 of 1

require function

Posted: Thu Aug 09, 2007 12:00 pm
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

Posted: Thu Aug 09, 2007 12:14 pm
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.

Posted: Thu Aug 09, 2007 12:31 pm
by bouncer
i just want to open content.php inside another page, e.g. main.php, when i go to tab1

thanks in advance

Posted: Thu Aug 09, 2007 1:00 pm
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.';
}
?>

Posted: Fri Aug 10, 2007 8:36 am
by bouncer
now is working thank you both :wink:

Posted: Fri Aug 10, 2007 12:30 pm
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

Posted: Wed Aug 15, 2007 5:31 am
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

Posted: Wed Aug 15, 2007 5:34 am
by VladSun
Read about AJAX :)

Posted: Wed Aug 15, 2007 7:05 am
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.