I am trying to recover some data from mysql , add them and show them by means of a query ajax
Javascript
$(function () {
$("#previousdate").on("click",function(){
$.ajax({
type: "POST",
url: base_url + 'index.php/welcome/showVentas',
data:{
'fecha' : $("#dateindex").val(),
},
success:function(e){
alert(e);
},
error:function(e){
alert("error");
}
});
}
});
php:
function showVentas()
{
$fecha = $_POST['fecha'];
$fecha2 = explode("/", $fecha);
$inicio = $fecha2[2] . "-" . $fecha2[1] . "-" . $fecha2[0] . " 00:00:00";
$fin = $fecha2[2] . "-" . $fecha2[1] . "-" . $fecha2[0] . " 23:59:59";
$statement = "SELECT cash FROM pr_gadgets_information WHERE created <= '$fin' && created >= '$inicio'";
$query = $this->db->query($statement);
$result = 0;
while ($fila = $query->fetch_assoc())
{
$result += $fila['cash'];
}
echo $result;
}
I think the error is in my function