Within my system, the user logs in, some information fetched from my database is shown, the function that searches the data and how it is listed follows:
Function
# função que busca os dados de originação no banco
function listaDadosOriginacao($conexao){
$dados = array(); //pode ser [] também, mas por compatibilidade, array()
$rede = $_SESSION['redeSelecionada'];
$codLoja = $_SESSION['lojaSelecionada'];
$mes = $_SESSION['mesSelecionado'];
$resultado = mysqli_query($conexao, "SELECT * FROM evolucao_originacao WHERE codLoja = {$codLoja} AND rede = '{$rede}' AND mesReferencia = '{$mes}'");
while($valores = mysqli_fetch_assoc($resultado)){
array_push($dados, $valores);
}
return $dados;
};
Listing (a single example since all data belongs to the same array)
<div class="col-lg-2 col-md-6 col-sm-6 col-xs-12">
<a class="dashboard-stat dashboard-stat-v2 green" href="#">
<div class="visual">
<i class="fa fa-shopping-cart"></i>
</div>
<div class="details">
<div class="number"><span data-counter="counterup" data-value="<?=number_format($dadosOriginacao['propostasAprovadas'],0,',','.')?>">0</span></div>
<div class="desc"># Aprovadas</div>
</div>
</a>
</div>
I have two dropdowns that filter data and when I click a button, it goes to the bank via an AJAX request and searches all the data in the same table that I use to enter information for the user and filters using the values selected in the dropdown.
Here's what I already have from the AJAX request:
$("#botao-filtrar").click(function(){
$(".mask-loading").fadeToggle(1000);
$.ajax({
url: 'datacenter/functions/filtraDashboardGeral.php',
async: true,
type: 'POST',
dataType: 'JSON',
data: {rede: $("#dropdown-parceria").val(), codLoja: $("#dropdown-loja").val(), mes: $("#dropdown-mes").val()},
success: function(data){
}
});
});
And this is the document quoted
filtraDashboardGeral.php
<?php
session_start();
require_once('../../includes/gestaoOriginacao.php');
$rede = $_POST['rede'];
$codLoja = $_POST['codLoja'];
$mes = $_POST['mes'];
$dados = array();
$resultado = mysqli_query($conexao, "SELECT * FROM evolucao_originacao WHERE redeTratada = '{$rede}' and codLoja = {$codLoja} and mesReferencia = '{$mes}'");
while($valores = mysqli_fetch_assoc($resultado)){
array_push($dados, $valores);
}
What I'm trying to do is have ajax return the data to me and fill in the new values in the variables I'm already using for listing without needing to reload my page!
I know it's a bit complex and I've been busting my head with it for weeks and nothing works. I am a beginner in this area of asynchronous requests.
Any solution or suggestion for improvement?