Jump to content

[SOLVED] Question about include


Anzeo

Recommended Posts

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

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');
?>

@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

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.

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?

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.

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 :D

 

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?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.