<html>
<form action="#" method="get" id="laser_finder">
<!-- Operating Mode -->
<div class="form-control main title">
Operating Mode
</div>
<!-- START CW -->
<div class="form-control">
<input type="checkbox" name="cw" class="laser_operating_mode" id="cw" value="CW (Continuous Wave)" >
<label for="cw">
CW (Continuous Wave)
</label>
</div>
<!-- START Pulsed -->
<div class="form-control">
<input type="checkbox" class="laser_operating_mode" name="pulsed" id="pulsed" value="Pulsed" >
<label for="pulsed">
Pulsed
</label>
</div>
The jQuery
<script>
$(document).ready(function(){
$( ".laser_operating_mode" ).change(function (e) {
e.preventDefault();
function laser_finder() {
$.ajax({
type: 'GET',
url: '{site_url}/ajax/laser_finder.php',
data: {action:"laser_finder"},
dataType: 'json',
success:function(data) {$('#results').html(data);}
});
}
laser_finder();
});
});
</script>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$action=$_GET["action"];
if($action=="laser_finder") {
$cw = $_GET['cw'];
$pulsed = $_GET['pulsed'];
$laser_query = ee()->db->select('entry_id')
->from('exp_matrix_data');
->where('col_id_6401', $cw)
->where('col_id_6401', $pulsed)
->get();
foreach($laser_query->result_array() as $row){
echo $row['entry_id'];
}
}
?>
<div class="select-input">
<form action="#" method="get" id="laser_finder">
<!-- Operating Mode -->
<div class="form-control main title">
Operating Mode
</div>
<!-- START CW -->
<div class="form-control">
<input type="checkbox" name="cw" class="laser_operating_mode" id="cw" value="CW (Continuous Wave)" >
<label for="cw">
CW (Continuous Wave)
</label>
</div>
<!-- START Pulsed -->
<div class="form-control">
<input type="checkbox" class="laser_operating_mode" name="pulsed" id="pulsed" value="Pulsed" >
<label for="pulsed">
Pulsed
</label>
</div>
</form>
</div>
<div id="results"></div>
jQuery at the top of the HTML<script>
$(document).ready(function(){
$( "#laser_finder" ).change(function (event) {
event.preventDefault();
function laser_finder() {
$.ajax({
type: 'GET',
url: '{site_url}/ajax/laser_finder.php',
data: {action:"laser_finder"},
dataType: 'html',
success:function(result) {
$('#results').html(result)
}
});
}
laser_finder();
});
});
</script>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$cw ='';
$pulsed = '';
$action=$_GET["action"];
if($action=="laser_finder") {
$cw = $_GET['cw'];
$pulsed = $_GET['pulsed'];
$laser_query = ee()->db->select('entry_id')
->from('exp_matrix_data')
->where('col_id_6401', $cw)
->get();
$laser_finder = $laser_query->result_array();
foreach($laser_query->result_array() as $row){
echo $row['entry_id'].'<br />;
}
}
?>
<script>
$(function(){
$( "#laser_finder" ).change(function (event) {
event.preventDefault();
var data = $(this).serialize();
laser_finder(data);
});
});
// PASS DATA TO FUNCTION
// AND POST IT
function laser_finder(data) {
$.ajax({
type: 'POST',
// ADD ACTION AS GET PARAMETER
url: 'laser_finder.php?action=laser_finder',
data: data,
dataType: 'html',
success:function(result) {
$('#results').html(result)
}
});
}
</script>
PHP - modified to not interface to CI - you will need to put that back in<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$cw ='';
$pulsed = '';
$action=isset($_GET["action"]) ? $_GET["action"] : '';
if($action=="laser_finder") {
$cw = isset($_POST['cw']) ? $_POST['cw'] : '';
$pulsed = isset($_POST['pulsed']) ? $_POST['pulsed'] : '';
// REPLACE WITH CI CODE
$laser_query = new stdClass;
$laser_query = array (
array('entry_id' => 1),
array('entry_id' => 3),
array('entry_id' => 4)
);
foreach($laser_query as $row){
// MISSING ' INSERTED
echo $row['entry_id'].'<br />';
}
// END REPLACE
}
Also, your PHP looks ... not so great. At the very least, you need to remove the semicolon from the line:
Open in new window
There may be other issues, hard to tell from that snippet.Take care of those things, then let us know how it goes.
If you need more help, we will need to see more of the PHP, like what you're including, etc, as well as the relevant HTML also, thanks!