Mutley Posted November 20, 2006 Share Posted November 20, 2006 If I try to do this:[code=php:0]include('folder/file.php?id=1');[/code]It will say not found, how do I allow the use of the URL extensions like ?id=....? Quote Link to comment https://forums.phpfreaks.com/topic/27907-inlcuding-variable/ Share on other sites More sharing options...
Psycho Posted November 20, 2006 Share Posted November 20, 2006 You don't. You could set $id before including the page. Then have the page act on the value of $id. Quote Link to comment https://forums.phpfreaks.com/topic/27907-inlcuding-variable/#findComment-127619 Share on other sites More sharing options...
Philip Posted November 20, 2006 Share Posted November 20, 2006 Yup, that's how I had to do it:[code]<?php$id = '1';include('folder/file.php');?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/27907-inlcuding-variable/#findComment-127630 Share on other sites More sharing options...
Mutley Posted November 20, 2006 Author Share Posted November 20, 2006 So can I do this, if I wanted to include several?<?PHP$id = '1';include('folder/file.php');$id = '2';include('folder/file.php');$id = '3';include('folder/file.php');?> Quote Link to comment https://forums.phpfreaks.com/topic/27907-inlcuding-variable/#findComment-127642 Share on other sites More sharing options...
Philip Posted November 20, 2006 Share Posted November 20, 2006 Well, are you including different files, or all from the same file? Quote Link to comment https://forums.phpfreaks.com/topic/27907-inlcuding-variable/#findComment-127643 Share on other sites More sharing options...
Destramic Posted November 20, 2006 Share Posted November 20, 2006 do this:index.php?id=01[code]<?phpswitch($_GET['id']){ case "01": require_once "file1.php"; break; case "02": require_once "file2.php"; break;}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/27907-inlcuding-variable/#findComment-127648 Share on other sites More sharing options...
Psycho Posted November 20, 2006 Share Posted November 20, 2006 [quote author=Mutley link=topic=115687.msg471101#msg471101 date=1164064613]So can I do this, if I wanted to include several?<?PHP$id = '1';include('folder/file.php');$id = '2';include('folder/file.php');$id = '3';include('folder/file.php');?>[/quote]If you need to include a "page" several times using a different variable I would think it would be more efficient to create a function for whatever the included page is doing. But, yes, you could do that IF you don't have any elements that can't be repeated in a single call - for instance you can't declare a function twice. Quote Link to comment https://forums.phpfreaks.com/topic/27907-inlcuding-variable/#findComment-127652 Share on other sites More sharing options...
Destramic Posted November 20, 2006 Share Posted November 20, 2006 well then i would do something like this:<?phpswitch($_GET['id']){ case "1": require_once "folder/file.php"; break; case "2": require_once "folder/file.php"; break; case "3": require_once "folder/file.php"; break;}?> Quote Link to comment https://forums.phpfreaks.com/topic/27907-inlcuding-variable/#findComment-127653 Share on other sites More sharing options...
Mutley Posted November 21, 2006 Author Share Posted November 21, 2006 [quote author=Destramic link=topic=115687.msg471112#msg471112 date=1164065486]well then i would do something like this:<?phpswitch($_GET['id']){ case "1": require_once "folder/file.php"; break; case "2": require_once "folder/file.php"; break; case "3": require_once "folder/file.php"; break;}?>[/quote]Doesn't show anything doing that, no errors. This is for the same file, just different URL extensions. Quote Link to comment https://forums.phpfreaks.com/topic/27907-inlcuding-variable/#findComment-127886 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.