Jump to content

Add variable to url without reloading page


idm1

Recommended Posts

Hi

 

How can I carry out this code without reloading the page:

<ul>
  <li><a href="?page=1">link 1</a></li>
  <li><a href="?page=2">link 2</a></li>
  <li><a href="?page=3">link 3</a></li>
  <li><a href="?page=4">link 4</a></li>
</ul>

  <?php
        $page=$_GET['page'];
        if ($page == '1'){
             include 'includes/page1.php';
        }
        if ($page == '2'){
            include 'includes/page2.php';
        }
        if ($page == '3'){
            include 'includes/page3.php';
        }
        if ($page == '4'){
            include 'includes/page4.php';
        }
   ?>

Or can someone advise a better way to include and page when a link is clicked?

 

Many thanks

 

If I'm following your logic.  when the web user clicks link 1, you want to load "include/page1.php".  PHP is a server side technology. In order to run the that pages code, your either have to reload or user a asynchronous programming model like AJAX.  AJAX can execute code in the background.

 

Look into JQuery $.ajax as possible solution.

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.