MySQL queries being killed by addition of "if" con

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

MySQL queries being killed by addition of "if" con

Post 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!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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
User avatar
mattcooper
Forum Contributor
Posts: 210
Joined: Thu Mar 17, 2005 5:51 am
Location: London, UK

Post by mattcooper »

It really was as simple as that!

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