Enviado em 19/12/2013 - 16:22h
<?php
$sql5 = mysql_query('select * from contratos where cliente = '.$id.' AND (select vencimento from contratos where cliente = '.$id.') >= CURRENT_DATE AND (select active from contratos where cliente = '.$id.') == 1');
if (mysql_result($sql5, 0) > 0) { echo '<img src="imgs/on.png" style="width: 25px; height: 25px;">'; } else { echo '<img src="imgs/off.png" style="width: 25px; height: 25px;">'; }
?>
$sql5 = mysql_query('select * from contratos where cliente = '.$id.' AND (select vencimento from contratos where cliente = '.$id.') >= CURRENT_DATE AND (select active from contratos where cliente = '.$id.') == 1');
if (mysql_result($sql5, 0) > 0) { echo '<img src="imgs/on.png" style="width: 25px; height: 25px;">'; } else { echo '<img src="imgs/off.png" style="width: 25px; height: 25px;">'; }
?>
Tabela clientes:
id (int, pk) / nome (varchar)
Tabela contratos:
id (int, pk) / cliente (int, fk: clientes/id) / vencimento (date YYYY-mm-dd) / active (int)
O $id vem de um while com todos os ids cadastrados.
O que eu quro fazer:
Imagem ON se todos os contratos estiverem no prazo de validade (data venc > data atual) e para os contratos ativos (active = 1).
Imagem OFF se pelo menos 1 contrato ativo (active = 1) estiver vencido. Se active = 0, ignorar a checagem.
Não funciona de jeito nenhum, recebo este erro:
Warning: mysql_result() expects parameter 1 to be resource, boolean given in index.php on line 57
Linha 57:
if (mysql_result($sql5, 0) > 0) { echo '<img src="imgs/on.png" style="width: 25px; height: 25px;">'; } else { echo '<img src="imgs/off.png" style="width: 25px; height: 25px;" alt="Contrato(s) Vencido!">'; }
Valew galera!!!