otis otis - 2 years ago 95
PHP Question

Auto reload included page after changing $_GET

I need to reload included page in after user clicks the specific link, which changes the tournament id.


$tournament = $_GET['tournament'];
$user = $_SESSION['user_id'];
$sql=$conn->query("SELECT *, SUM(points) as total FROM results WHERE tournament_id = '$tournament' and user_id = '$user' ");
echo 'Logged user '. $_SESSION['name'] .', score '. $data->total . 'in tournament '. $data->tournament_name; ?>

in main layout I have:

<div id="info">
<?php include "info.php"; ?>

<div id="main">Select tornament:
<a href="competition.html?tournament=1">Tournament 1</a><br />
<a href="competition.html?tournament=2">Tournament 2</a><br />

I need to automatically refresh div where page "info.php" loads to get logged user's points from chosen tournament.

Answer Source

You cannot re-execute an included PHP script once the page is generated and loaded. So you have two solutions:

  1. Use AJAX to request the info.php from the server and then insert the received content in the DIV using JavaScript:


  2. Use IFRAME instead of DIV and reload it when needed.


<IFRAME id="info" src="info.php"></IFRAME>


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