• 0
Sign in to follow this  
rbiaggio

Query SUM(IF( ))

Question

Pessoal,

Eu estou com problema na minha página PHP quando altero minha query.

Funciona OK:

"SELECT nome_disco,  group_concat(status_disco) AS 'Monitores' from tb_disco_windows WHERE (`id_solic_disco_windows` = '". $id_solic ."' AND hostname_server='". $hostname ."') GROUP BY nome_disco";

Ocorre erro:

$query_windows = "SELECT nome_monitor_infra,  SUM(IF( status_monitor_infra = "Critical", 1, "" )) AS Critical, SUM(IF( status_monitor_infra = "Warning", 1, "")) AS  Warning from tb_infra_windows WHERE (`id_solic_infra_windows` = '". $id_solic ."' AND hostname_server='". $hostname ."') GROUP BY nome_monitor_infra";

Não sei o que pode ser.

Segue o código inteiro do mysql:

$query_windows = "SELECT nome_monitor_infra,  SUM(IF( status_monitor_infra = "Critical", 1, "" )) AS Critical, SUM(IF( status_monitor_infra = "Warning", 1, "")) AS  Warning from tb_infra_windows WHERE (`id_solic_infra_windows` = '". $id_solic ."' AND hostname_server='". $hostname ."') GROUP BY nome_monitor_infra";
$result_windows = mysql_query($query_windows, $conecta) or die(mysql_error());
$rows_query_windows = mysql_fetch_assoc($result_windows);
$totalRows_query_windows = mysql_num_rows($result_windows);

 

Apenas complementando, um pouco mais abaixo eu tenho um While aonde mostro o resultado dessa query:

			<?php
				do
				{
			?>
			<tbody>
				<tr>
					<td><?php echo $rows_query_windows['nome_monitor_infra'];?></td>
						<td>
							<?php
								if (($rows_query_windows['Critical'] == '1'){
									echo "<img src='images/check.png'>";
									}
								elseif($rows_query_windows['Monitores'] == '0') {
									echo "Não existem monitores cadastrados";
									}
								else {
									echo "<img src='images/delete_button.png'>";					
									}	
							?>
						</td>
						<?php
							} 
							while ($rows_query_windows = mysql_fetch_assoc($result_windows));
								$rows = mysql_num_rows($result_windows);
									if($rows > ) {
										mysql_data_seek($result, );
										$rows_query_windows = mysql_fetch_assoc($result_windows);
										}		
						?>

 

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Estás a misturar aspas duplas com aspas simples. Se usas aspas duplas para delimitar a string, dentro desta tens de usar aspas simples. Se reparares, as expressões Critical e Warning não estão a ser interpretados como fazendo parte da string.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this