0
I need to pass some arguments through Ajax, at first the code presents syntax error.
var comeco = $("data_filtroe").val();
var fim = $("data_filtrod").val();
jQuery.ajax({
type: "get",
url: "status_relatorio.php",
data: "comeco="+comeco+" && fim="+fim,
success: function(data){
document.querySelector('#status_dia').innerHTML = data;
}
});
PHP code("status_report.php"):
<?php
session_start();
$con = mysql_pconnect("localhost","root","eeep_#2017");
mysql_query("SET NAMES 'utf8'");
mysql_query('SET character_set_connection=utf8');
mysql_query('SET character_set_client=utf8');
mysql_query('SET character_set_results=utf8');
mysql_select_db("alunos",$con);
setlocale( LC_ALL, 'pt_BR', 'pt_BR.iso-8859-1', 'pt_BR.utf-8', 'portuguese' );
date_default_timezone_set( 'America/Fortaleza' );
$data_inicio = $_GET['comeco'];
$data_fim = $_GET['fim'];
$data="";
for ($i=$data_inicio; $i <= $data_fim; $i++) {
if($data==""){
$data = "data = ".$i;
}else{
$data = "and data = ".$i;
}
}
if($data_inicio==$data_fim){
$data = "data=".$data_inicio;
}
$sql = "select * from ocorrencias where '$data' order by curso, nome_aluno asc";
$resultado = mysql_query($sql,$con);
$cont = 0;
$falta = 0;
$falta_justificada = 0;
$fardamento_incompleto = 0;
$es_autorizada = 0;
$indis = 0;
while($linha1 = mysql_fetch_array($resultado)){
$cont++;
if($linha1['tipo']=="Falta"){
$falta++;
}
if($linha1['tipo']=="Falta Justificada"){
$falta_justificada++;
}
if($linha1['tipo']=="Fardamento Incompleto"){
$fardamento_incompleto++;
}
if($linha1['tipo']=="Entrada/Saída Autorizada"){
$es_autorizada++;
}
if($linha1['tipo']=="Indisciplína"){
$indis++;
}
}
echo "<table cellpadding='3' id='status_dia'>
<tr>
<td class='status'>Faltas: <label>".$data_inicio."</label></td>
<td class='status'>Faltas Justificadas: <label>".$falta_justificada."</label></td>
<td class='status'>Fardamentos Incompletos: <label>".$fardamento_incompleto."</label></td>
<td class='status'>Entradas/Saídas Autorizadas: <label>".$es_autorizada."</label></td>
<td class='status'>Indisciplína: <label>".$indis."</label></td>
<td class='status'>Total: <label>".$cont."</label></td>
</tr>
</table>";?>
It still didn’t work out. Error : Notice: Undefined index: comeco in C: xampp htdocs Sistema - Controle Geral de Alunos status_relatorio.php on line 11 Notice: Undefined index: fim in C: xampp htdocs Sistema - Controle Geral de Alunos status_relatorio.php on line 12
– Carlos Henrique
I did this... receive code... $data_start = $_GET['start']; $data_end = $_GET['end'];
– Carlos Henrique
@Have a look at my answer and my comments on it. Use
$_POST["comeco"]
,$_POST["fim"]
.– Godfrey the King
Another thing... There are numerous errors in your code. The most serious is that you are using the extension
mysql
which has been completely removed in PHP 7 and deprecated since version 5.4 of it.– Godfrey the King
Another thing... It is much easier, simple, fast and practical you perform a separate consultation based on
tipo de falta que você quer
... Or useCOUNT()
andGROUP BY
.– Godfrey the King
@Godfreytheking I can’t use the group by function because I need to show exactly all values.
– Carlos Henrique
Like I said... you can use
COUNT()
based on the type you want and group them. You have 5 different types, right? You just count the lines that have thetipo X
and group in this type, accounts the lines that have thetipo Y
and group together. In this way,SELECT
will return only 5 lines.– Godfrey the King