I have a PHP file that returns a Json.
This PHP file is called by Ajax, I do not have functions in the PHP file. I get the POST variables in the PHP file ...
This is all working, but now I want to add in PHP functions and receive the data by parameter, at the moment I'm doing so:
var pesquisa = $("#pesquisa").serialize();$.ajax({
type: "POST",
url: "../Logica/info/Getinfo.php",
dataType: 'json',
data: pesquisa,
Of course, in the PHP file I do not have classes or functions,
in PHP I get the parameters by $var= $_POST["key"];
Now I want to put the file with functions and keep it working ... How can I do this?
function getinfo($key,$query,$datainicio,$datafim,$op){
if ($op != "" and ( $datainicio != "" and $datafim != "")) {
$query = "$querys $op and (datainicio >:datainicio AND datafim<:datafim)";
$db = new ligacao();
$conn = $db->open();
$stmt = $conn->prepare($query);
$stmt->bindParam(':datainicio', $datainicio, PDO::PARAM_STR);
$stmt->bindParam(':datafim', $datafim, PDO::PARAM_STR);
}
if ($key != "") {
$query = "$querys KEY=:KEY";
$db = new ligacao();
$conn = $db->open();
$stmt = $conn->prepare($query);
$stmt->bindParam(':KEY', $key, PDO::PARAM_STR);
}
$stmt->execute();
$result = $stmt->fetchAll();
$table = array();
$rows = array();
foreach ($result as $row) {
$rows[] = $row;
}
$table['data'] = $rows;
$json = json_encode($table);
echo ($json);
}