Hello Im trying to get my textboxes to work with a search option in the database via AJAX.
Im not getting it to work on multiple textboxes, only with one.
This is my code, maby you guys can help me getting it to work. That would be great.
php
<?php
$pdo = new PDO('mysql:host=localhost;dbname=records', 'root', 'l3tm31n');
$select = 'SELECT *';
$from = ' FROM overboekingen';
$opts = (isset($_POST['filterOpts']) ? $_POST['filterOpts'] : FALSE);
$val = (isset($_POST['text']) ? $_POST['text'] : FALSE);
if ($val != null){
$where = " WHERE boekingsnummer LIKE '".$val."%'";
}
elseif ($val != null){
$where = " AND huiscode LIKE '".$val."%'";
}
else {
if (is_array($opts) || $val){
$where = ' WHERE FALSE';
else {
$where = false;
}
}
$sql = $select . $from . $where;
$statement = $pdo->prepare($sql);
$statement->execute();
$results = $statement->fetchAll(PDO::FETCH_ASSOC);
$json = json_encode($results);
echo($json);
html
<ul id="boekingsnummer" class="hide">
<li><label>Boekingsnummer</label></li>
<li><input type="text" name="boekingsnummer" size="20" id="boekingsnummer_1">
<div class="suggestionsBox" id="suggestions2" style="display: none;">
<div class="suggestionList" id="autoSuggestionsList2"></li>
</ul>
<ul id="huiscode" class="hide">
<li><label>huiscode</label></li>
<li><input type="text" name="huiscode" size="20" id="huiscode_1" >
<div class="suggestionsBox" id="suggestions5" style="display: none;">
<div class="suggestionList" id="autoSuggestionsList5"></li>
</ul>
ajax
$('#boekingsnummer_1').keyup(function(){
updateEmployeesText($(this).val());
});
$('#huiscode_1').keyup(function(){
updateEmployeesText($(this).val());
});
function updateEmployeesText(val){
$.ajax({
type: "POST",
url: "submit.php",
dataType : 'json',
cache: false,
data: {text: val},
success: function(records){
$('#employees tbody').html(makeTable(records));
}
});
}