-2
It is calling only an if option.
1 = >all users by date = if empty user and date filled (only this calling and msm so a user has q be selected, what is wrong the user had to be empty)
2 = > user per date = user completed and date completed
3 = >only the user = completed user and empty date. Everything else returns nothing.
the code is like this now:
if (isset($_POST['busca']) && !empty($_POST['busca'])){
//todos usuarios por periodo
$sql = "SELECT * FROM assentamentos a, usuarios u, ocorrencias o, problemas p, localizacao l, instituicao i, sistemas s WHERE o.data_abertura BETWEEN '$ymdinicio' AND '$ymdfim' and a.responsavel = u.user_id and a.data = o.data_fechamento and p.prob_id = o.problema and o.local = l.loc_id and i.inst_cod = o.instituicao and s.sis_id = o.sistema ORDER BY o.numero DESC";
}
else if(isset($_POST['data_inicial']) && !empty($_POST['data_inicial']) and isset($_POST['data_final']) && !empty($_POST['data_final'])){
//so usuario
$sql = "SELECT * FROM assentamentos a, usuarios u, ocorrencias o, problemas p, localizacao l, instituicao i, sistemas s WHERE u.nome = '$busca' and a.responsavel = u.user_id and a.data = o.data_fechamento and p.prob_id = o.problema and o.local = l.loc_id and i.inst_cod = o.instituicao and s.sis_id = o.sistema ORDER BY o.numero DESC";
}
else{
//usuario por periodo
$sql = "SELECT * FROM assentamentos a, usuarios u, ocorrencias o, problemas p, localizacao l, instituicao i, sistemas s WHERE o.data_abertura BETWEEN '$ymdinicio' AND '$ymdfim' and u.nome = '$busca' and a.responsavel = u.user_id and a.data = o.data_fechamento and p.prob_id = o.problema and o.local = l.loc_id and i.inst_cod = o.instituicao and s.sis_id = o.sistema ORDER BY o.numero DESC";
}
print "<table width='100%' border='0' align='center' cellpadding='1' cellspacing='2' class='full_table_list'>";
print "<tr class='tabela_cinza'>";
print "<td align='center' colspan='10'><span class='texto_negrito'>Relatório Geral</span></td>";
print "</tr>";
print "<tr>";
print "<td align='center' width='8%'><span class='texto_negrito'>Número</span></td>";
print "<td align='center' width='8%'><span class='texto_negrito'>Técnico</span></td>";
print "<td align='center' width='8%'><span class='texto_negrito'>Problema</span></td>";
print "<td align='center' width='16%'><span class='texto_negrito'>Descriçao do problema</span></td>";
print "<td align='center' width='16%'><span class='texto_negrito'>Soluçao do Problema</span></td>";
print "<td align='center' width='8%'><span class='texto_negrito'>Área</span></td>";
print "<td align='center' width='8%'><span class='texto_negrito'>Unidade</span></td>";
print "<td align='center' width='12%'><span class='texto_negrito'>Local</span></td>";
print "<td align='center' width='8%'><span class='texto_negrito'>Data inicial</span></td>";
print "<td align='center' width='8%'><span class='texto_negrito'>Data final</span></td>";
print "</tr>";
print "</table>";
$qr = mysql_query($sql) or die(mysql_error());
while ($linha = mysql_fetch_array($qr)) {
print "<form action='' method='post' name='CadInfo' target='_parent' id='CadInfo'>";
print "<table width='100%' border='0' align='center' cellpadding='1' cellspacing='2' class='full_table_list'>";
print "<tr>";
print "<td align='center' width='8%'><span class='texto_center'>".$linha['numero']."</span></td>";
print "<td align='center' width='8%'><span class='texto_center'>".$linha['nome']."</span></td>";
print "<td align='center' width='8%'><span class='texto_center'>".$linha['problema']."</span></td>";
print "<td align='center' width='16%'><span class='texto_center'>".$linha['descricao']."</span></td>";
print "<td align='center' width='16%'><span class='texto_center'>".$linha['assentamento']."</span></td>";
print "<td align='center' width='8%'><span class='texto_center'>".$linha['sistema']."</span></td>";
print "<td align='center' width='8%'><span class='texto_center'>".$linha['inst_nome']."</span></td>";
print "<td align='center' width='12%'><span class='texto_center'>".$linha['local']."</span></td>";
print "<td align='center' width='8%'><span class='texto_center'>".$linha['data_abertura']."</span></td>";
print "<td align='center' width='8%'><span class='texto_center'>".$linha['data_fechamento']."</span></td>";
print "</tr>";
print "</table>";
print "</form>";
}
A great weekend for everyone.
The blocks ,
if, else if e else
are mutually exclusive or when entering one the others are ignored. Only in theelse
the query is executed and iterated, seems to be the problem.– rray
I don’t have much knowledge, but I think the problem is that in the middle of the
if
you used theand
, unlike a&&
.– David
The operator
and
exists but is different from&&
, follows documentation: Operators– David
These are 3 query options that I have to check, I used if pq it only has to run 1 of them: 1 query only by the user 2 query the user by date 3 query all users by date
– Igor Santos
In two options the
mysql_query()
and themysql_fetch_assoc()
– rray
could give me an example of how it should be?
– Igor Santos