This is a snippet from my index.php
page, where I'm displaying a menu with three HTML links.
Selecting a menu item defines the page parameter, which the PHP templating logic then loads, populating into <div id="main">
.
<div class="span-24" id="menu">
<table>
<tr>
<td><a href="index.php?page=races">Races</a></td>
<td><a href="index.php?page=runners">Runners</a></td>
<td><a href="index.php?page=searchRunners">Search</a></td>
</tr>
</table>
<br/>
</div>
<!-- main content -->
<div class="span-24" id="main">
<?php
$MYROOT=$_SERVER['DOCUMENT_ROOT'];
if(isset($_GET['page']))
{
$page=$_GET['page'];
@ require_once($MYROOT."/$page.php");
}
else
{
@ require_once($MYROOT."/races.php");
}
?>
</div>
This solution works fine, but I'm worried that as I add more pages and have more page parameters to track, this approach will become difficult to maintain with the various PHP require()
/ require_once()
method calls.
I also have jQuery available and I was wondering what could be the benefits or drawbacks of just using a AJAX based query to render the HTML for <div id="main">
.
I think using AJAX might be a better solution, since I'll have more flexibility in the page that I can call and which parameters I can pass within the AJAX call.
I know PHP and the AJAX can be used together, but if you were starting this type of project, how would you do it?