jvr jvr - 6 months ago 34
PHP Question

How to change page content in PHP?

I have a master page that has a content division. Depending on which menu item is clicked, I would like to change the content accordingly.

Example: If "About us" is clicked then I would include the about us content in the content



On PHP without JS. You will need to pass a page identifier by POST or GET methods

Click on such a link on a page will send a GET request to masterpage called index.php with variable 'content_id' of 'about' value

<a href="index.php?content_id=about">About Us</a>

In the PHP script you will need to get by PHP this variable from web server. like

    $content=$_GET['content_id']; // _GET is web server array with get variables

in the content section of your master page there could be an 'if' or 'case' construction which will include a required content

    if ($content == 'about'){
    echo "About We are the Best";
    // you could include a file or data from database here
    echo "Some other page";

p.s. PHP has a lot of already mature frameworks with templates, no need to write one from scratch :-)