I'm a FileMaker programmer trying to port a database across to the web using PHP their API. I've got my php page working, retrieving and displaying the correct data from my search, however I would like to filter the results on my page every time my user picks a checkbox (Apple, Microsoft etc) without hitting the submit button. I know I need to use ajax to perform this, however can I inject the ajax into this page below or am I now going to have to break down the page into various smaller files, php and js files?
Most of the samples I have found are json based, which do filtering client side. FileMaker returns an odd type array with PHP which requires further processing to get into json format. I'm ideally looking for a way to just post back the form everytime my user click on a checkbox, which I think maybe simpler if possible?
<?php require_once('../db.php');
if(isset($_REQUEST['search'][0]))
{
$find = $fm->newCompoundFindCommand('Data');
$request1 = $fm->newFindRequest('Data');
if(isset($_REQUEST['search'][1])){ $request2 = $fm->newFindRequest('Data'); }
if(isset($_REQUEST['search'][2])){ $request3 = $fm->newFindRequest('Data'); }
$request1->addFindCriterion('Company',$_REQUEST['search'][0]);
if(isset($_REQUEST['search'][1])){ $request2->addFindCriterion('Company',$_REQUEST['search'][1]); }
if(isset($_REQUEST['search'][2])){ $request3->addFindCriterion('Company',$_REQUEST['search'][2]); }
$find->add(1,$request1);
if(isset($_REQUEST['search'][1])){ $find->add(2,$request2); }
if(isset($_REQUEST['search'][2])){ $find->add(3,$request3); }
$result = $find->execute();
} else {
$request = $fm->newFindCommand('Data');
$request->addFindCriterion('Company','*');
$result = $request->execute();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
</head>
<body>
<div id="filters">
<form action="data_table.php" method="post">
<input class="category" id="check1" name="search[]" type="checkbox" value="Apple">
<label for="check1">Apple</label>
<input class="category" id="check2" name="search[]" type="checkbox" value="Google">
<label for="check2">Google</label>
<input class="category" id="check3" name="search[]" type="checkbox" value="Microsoft">
<label for="check3">Microsoft</label> <input type="submit" value="Submit">
</form>
</div>
<table border="0" class="table table-striped" width="100%">
<thead>
<tr>
<th>Company</th>
</tr>
</thead><?php if(!FileMaker::isError($result)) {?>
<tbody class="searchable">
<?php foreach($result->getRecords() as $row){ ?>
<tr>
<td><?php echo $row->getField('Company'); ?></td>
</tr><?php } ?>
</tbody><?php } ?>
</table><!-- end row -->
</body>
</html>