jvr jvr - 1 year ago 68
PHP Question

How to change only 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 ie.

If "About us" is clicked then I would include the about us content in the content div.

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download