[thelist] checking for empty vars in PHP

Tony Light TonyLight at blueyonder.co.uk
Fri Jan 3 12:12:01 CST 2003


--
[ Picked text/plain from multipart/alternative ]
On Fri, 3 Jan 2003 Tom Dell'Aringa 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!

I suspect you have nothing in your result set.
Therefore the while loop never gets executed.
Could try checking the number of rows in the result set first.
If 0 then print your message.
If not, do your while loop.

Regards,
Tony.

--




More information about the thelist mailing list