[thelist] checking for empty vars in PHP

sasha spam at bittersweet2.com
Fri Jan 3 11:03:01 CST 2003


On Fri, 3 Jan 2003 08:58:21 -0800 (PST), Tom Dell'Aringa
<pixelmech at yahoo.com> wrote:

> I have this result set I am looping through. If there is nothing in
> the set, I want to print out an message. Here is the code:
> --------------------------
> while($row = mysql_fetch_array($result))
> {
> $prodname = $row["prodName"];
> 	$prodprice = $row["prodPrice"];
> 	$pid = $row["pid"];
> 	$photo = $row["photo"];
>
> 	if(!isset($prodname))
> 	{
> 		print "registry is empty.";
> 	}
> //display stuff
> }
> --------------------------
>
> I am not getting the print statement at all with this, even though
> $prodname is blank or empty. I have tried
>
> if($prodname == "") and if(!$prodname) but these didn't work for me.
> Am I testing the wrong thing? $prodname certainly is = "" so I am
> totally confused!
>
> Tom
>
> =====
> var me = tom.pixelmech.webDeveloper();
>
> http://www.pixelmech.com/
> http://www.maccaws.com/
> [Making A Commercial Case for Adopting Web Standards]
>
> __________________________________________________
> Do you Yahoo!?
> Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
> http://mailplus.yahoo.com

Try if (empty($prodname)).  It's worth noting that a set value of zero
counts as empty.

--
sasha



More information about the thelist mailing list