Jump to content


Photo

include()


  • Please log in to reply
2 replies to this topic

#1 ChrisDarl

ChrisDarl
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 06 December 2005 - 01:44 PM

Does anyone know of a way to use URL variables in the function include(); or another similar function.

i.e.

include("./includes/leftMenu.php?item=21");

so that the item=21 will change something on the leftMenu.php page.


Many thanks, Chris

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 06 December 2005 - 01:58 PM

[!--quoteo(post=325053:date=Dec 6 2005, 08:44 AM:name=ChrisDarl)--][div class=\'quotetop\']QUOTE(ChrisDarl @ Dec 6 2005, 08:44 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Does anyone know of a way to use URL variables in the function include(); or another similar function.

i.e.

include("./includes/leftMenu.php?item=21");

so that the item=21 will change something on the leftMenu.php page.
Many thanks, Chris
[/quote]

you don't need to pass variables that way. think of it this way: when you include() or require() a file, the contents of that file become part of the current page. with that in mind, all the variables are shared, too. so, all you'd have to do is something like this:
<?php
$item = 21;
include("./includes/leftMenu.php");
?>

then, $item on leftMenu.php will already be set.

hope this helps your understanding a bit
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 ChrisDarl

ChrisDarl
  • Members
  • PipPip
  • Member
  • 27 posts

Posted 06 December 2005 - 04:30 PM

Thanks, yeah, i understand that. I really was after this sort of thing...

====page a.php=====

include("b.php?page=4");


====page b.php=====

if($_GET['page'] == "4")
{
     //include page four code in a.php;
}
else
{
    //include other pages in a.php
}

hope this helps you to understand what im trying to do more clearly.

Thanks for your reply obsidian




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users