Anzeo Posted April 16, 2007 Share Posted April 16, 2007 Hi, I've recoded the navigation of my site with a php switch function now, but I'm wandering if it would be possible to include a page that has variables assigned to it like post.php?mode=frm&id=1 is it possible to include such page linkings? I was thinking of something like <?php include("post.php?mode=$mode&id=$id"); ?> But it dosn't seem to work as it's saying that there's no such file, so my question is: is there a possibility to do so? Link to comment https://forums.phpfreaks.com/topic/47295-solved-question-about-include/ Share on other sites More sharing options...
per1os Posted April 16, 2007 Share Posted April 16, 2007 The real question is, is post.php in the same directory as the script is being ran? That and why try and pass them as get variables when this works: <?php $mode = "somemode"; $id = "someid" include('post.php'); ?> That would work out alright, if you wanted them to be like get data do this instead: <?php $_GET['mode'] = "somemode"; $_GET['id'] = "someid" include('post.php'); ?> Link to comment https://forums.phpfreaks.com/topic/47295-solved-question-about-include/#findComment-230692 Share on other sites More sharing options...
soycharliente Posted April 16, 2007 Share Posted April 16, 2007 @Anzeo: I think that when you tried adding those variables into the include, it tried looking for a page with that specific name. Link to comment https://forums.phpfreaks.com/topic/47295-solved-question-about-include/#findComment-230696 Share on other sites More sharing options...
Anzeo Posted April 16, 2007 Author Share Posted April 16, 2007 @Charlieholder: indeed that's causing the error @frost: post is in the same directory, but I don't understand how you would make your example work. I mean I need the code for example when you click on "post new reply" it brings you to the post page where I would use $_GET to get both the mode and the id out of my link. The "post new reply" button would be linked like this: post.php?mode=$mode&id=$id but when I try to include that file it causes the problem which charlieholder said Link to comment https://forums.phpfreaks.com/topic/47295-solved-question-about-include/#findComment-230707 Share on other sites More sharing options...
per1os Posted April 16, 2007 Share Posted April 16, 2007 If it is already in the GET statement and you are including the file you do not need to do anything. Simple include that file and the get data will be "included" into the include file. All you need to do is this: <?php if (isset($_GET['mod'])) include('post.php'); ?> Simple as that. Link to comment https://forums.phpfreaks.com/topic/47295-solved-question-about-include/#findComment-230713 Share on other sites More sharing options...
Anzeo Posted April 16, 2007 Author Share Posted April 16, 2007 Nono I don't think you understand me , I need to include a file that's linked to variables so I got a switch and it includes my pages (for naviagtion) when I'm on the forum or viewing a profile, I also want to use that same switch (that way I only need one site structure with header etc.) so when clicking on add reply it needs to include the post.php or in other cases, forum.php or profile.php. the links would look like http://.../index.php?page=post&mode=$mode&id=$id Is that realy possible, am I misunderstanding you and if so could you provide me with an example? Link to comment https://forums.phpfreaks.com/topic/47295-solved-question-about-include/#findComment-230726 Share on other sites More sharing options...
per1os Posted April 16, 2007 Share Posted April 16, 2007 Have you even tried what I suggested? profile.php <?php if (isset($_GET['mode'])) include('post.php'); ?> post.php <?php print_r($_GET); print_r($_POST); ?> Try that and see what prints out. Link to comment https://forums.phpfreaks.com/topic/47295-solved-question-about-include/#findComment-230728 Share on other sites More sharing options...
Wildbug Posted April 16, 2007 Share Posted April 16, 2007 Anzeo, If I understand what you're asking, from your original post, you wish for variables to be available to the included file. The include() statement is basically equivalent to replacing the "include('filename.php')" line with the contents of 'filename.php.' Therefore, any variables in the script up to that point are available in the included code as well. So... you don't need to "pass" variables to the included code; it already has them in its scope. Just include post.php. Link to comment https://forums.phpfreaks.com/topic/47295-solved-question-about-include/#findComment-230744 Share on other sites More sharing options...
Anzeo Posted April 16, 2007 Author Share Posted April 16, 2007 I think I got what you mean, sorry I'm such a stiff head. I have used my profile page to work on this example (as my post page is under coding) what I did now was I made my profile links like this: http://.../index.php?p=profile&id=$id and that worked^^ thanks for the help frost, you've helped me out now quite a couple of times I appreciate the help and time you've put into me so far! Back to coding Oh btw, I don't wan't to open a new post for it, but you've looked at my forum index too and I can get the results now but I can't seem to get my forums grouped/category. Do you have any idea on how to do that? the topic is named "error with while function" TIA! @ Wildbug: like the way I did now? Link to comment https://forums.phpfreaks.com/topic/47295-solved-question-about-include/#findComment-230745 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.