0
I have this script.
function execultaAjax() {
var fld_busca = document.getElementById("id_busca").value;
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("demo").innerHTML =
this.responseText;
}
};
xhttp.open("POST", "busca.php", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("fld_busca="+fld_busca);
}
However, it executes all the php code of the.php file. I would like to organize my querys into functions and perform them only when necessary and not all at once.
This is the search.php file
<?php
require 'config.php';
require 'conection.php';
require 'dataBase.php';
$fld_busca = isset($_POST["fld_busca"]) ? $_POST["fld_busca"] : "";
$sql = "SELECT * FROM tbl_ativo WHERE nome LIKE '%$fld_busca%' ORDER BY nome ASC";
$retorno = executaQuery ($sql);
while ($linha = mysqli_fetch_assoc($retorno)) $data [] = $linha;
foreach ($data as $value) {
echo "<option value= \"$value[id]\" > $value[nome] </option>";
}
?>
Did my answer work? Or did I misunderstand?
– Andrei Coelho