Page 1 of 1

MySQL queries being killed by addition of "if" con

Posted: Fri May 05, 2006 11:57 am
by mattcooper
Hi all,

I am trying to use this bit of code to check rows to see if there is a value set for "$row[imag_url]":

Code: Select all

$sqlbanners = "SELECT * 
			FROM {$ezine_id}_banners";

	$resultbanners = mysql_query($sqlbanners);
	$numbanners = mysql_num_rows($resultbanners);
	
	$i = 1;

	while($i <= $numbanners){
	$row = mysql_fetch_assoc($resultbanners);
	if($row[image_url]!=""){
?>
          <td width="50%" valign="middle"><div align="right"><a href="<? echo $row[redirect_url]; ?>" target="_blank"><img src="<? echo $row[image_url]; ?>" width="180" height="100" hspace="5" vspace="0" alt="Banner advertisement" border="0"></a></div></td>
          <?
$i++;
	}
}
If I remove the "if" conditional, the script runs fine and tries to display as many images as rows returned. However, if I replace the conditional, the page takes about twenty seconds to load, the conditional works, but the rest of the dynamic output for the page is missing. I suspect that this is a timeout issue or something similar, and wounder if there is another way to achieve what I am trying to do by using MySQL instead of php to look for empty fields and exclude them.

I'd love to know why the script/database/page is behaving like this, and also what the syntax should be in my MySQL query to eleiminate empty fields...

Thanks in advance!

Posted: Fri May 05, 2006 12:43 pm
by feyd
If there's nothing else using these specific $row values after this code,

Code: Select all

SELECT `image_url` FROM {$ezine_id}_banners WHERE `image_url` != '' AND `image_url` NOT NULL

Posted: Fri May 05, 2006 12:56 pm
by mattcooper
It really was as simple as that!

Feyd, you're a great help. Thank you.