質問

So I've search far and wide to try and find an example of this but found nothing. It seems like a simple thing however I continue to get errors.

Essentially what I've got is:

<?php 
    $articleCount = 3;
    include('/newsArticles.php?id=$articleCount'); 
?>

It seems fairly self explanatory. What I need is an include that I can pass a value on into the file which I can then grab with $_GET['id'].

役に立ちましたか?

解決

You can't add a query string (Something like ?x=yyy&vv=www) onto an include like that. Fortunately your includes have access to all the variables before them, so if $_GET['id'] is defined before you call:

include('/newsArticles.php');

Then newsArticles.php will also have access to $_GET['id'];

他のヒント

You don't need to pass a $_GET variable. Just set it, and reference it in your included file.

Your included file will have access to $articleCount without any additional work needed.

Try this:

$_GET['id'] = 3;
include('/newsArticles.php'); 

Since you are including a script it would seem as though you have access to the script itself. Even if you don't have access to the script you can edit the $_GET variable from within the script you showed above, like this:

<?php
    $_GET['id'] = 3; // or $_GET['id'] = $articleCount;
    include('/newsArticles.php');
?>

That's because the script newsArticles.php has the same access to the $_GET variable, unless the script was specifically created so that it extracts the variables from the URL.

Try it.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top