0

I have been experimenting with query strings to load content dynamically within a div on a page. A normal include without a query string works fine. However, when I add a query string and variable, a page is not returned. Is there an alternative method of doing this - if this is not possible

index.php

<a href="?blogs=1">BLOGS</a>

if (isset($_GET['blogs'])) {
    $link = $_GET['blogs'];
    if ($link == '1') {
        include('/controller/blogs/viewBlogs.php?blogid=$blogid');
        $linkclicked = true;
    }
}

index.php has a link to listBlogs.php which opens a list of blogs in index.php's content div with a query string linking to each individual blog. The query strings link to the viewBlogs.php page.

I.e. blogid=29.

listBlogs.php

<a href='/controller/blogs/viewBlogs.php?blogid=$blogid'>View blog '$title'</a>";

When clicking on a link in listBlogs.php it takes me to a separate page containing the specific information for the blogid in viewBlogs.php.

viewBlogs.php

I want the blogId taken from listBlogs.php to be taken and open the viewBlogs.php page with that specific blogid in the content div in the index.php page.

Thanks.

1
  • 1
    query strings pass data from browser(html) to server(php). to pass data from server(php page) code to another(php code), use functions. Commented Jan 6, 2016 at 8:25

1 Answer 1

2

Yes, define the variables beforehand (before your include call, that is):

if (isset($_GET['blogs'])) {
    $link = $_GET['blogs'];
    if ($link == '1') {
        $blogid="1234";
        include('/controller/blogs/viewBlogs.php');
        $linkclicked = true;
    }
}

Or use a superglobal like $_GET, $_POST or $_SESSION in viewBlogs.php directly (that's what it's all about in the first place anyway).

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, thanks for your reply. I have clarified my problem further above. This solution didn't work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.