[thelist] checking for empty vars in PHP

Tom Dell'Aringa pixelmech at yahoo.com
Fri Jan 3 11:22:03 CST 2003


--- mort <manuel at netbustion.com> wrote:
> El vie, 03-01-2003 a las 17:58, Tom Dell'Aringa escribió:
> > 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
> > }
> > --------------------------
> >
>
> isset() certainly won't work here because you're setting $prodname
> =
> $row["prodName"]
>
> if ($prodname==""){print "registry is empty.";}
> should work
>
> Debug by echoing $prodname in every condition, that should clarify
> everything

Strangely, even my test prints don't work within the while loop. Here
is a fuller picture of the code with my SQL query, below. Note where
you see me print the vars, I don't even get the "P: " or anything.

There are no items in registry that match this $uid at all - I'm
wondering if this means that the $row is empty, therefore it never
enters the while loop? if(!$result) wouldn't catch it because it was
a successful query and therefore has a resource, but there's no
data..does that makes sense? If so, how could I modify my while to
get the 'no items' to show?

-------------------
$result = @mysql_query("
SELECT
	prodtemp.prodName,
	prodtemp.prodPrice,
	prodtemp.prodtempID,
	prodtemp.pid,
	prodtemp.photo
FROM
	prodtemp
INNER JOIN
	registry ON registry.prodtempID = prodtemp.pid
WHERE
	reguserID = '$uid'");

if(!$result)
{
	print "There was an error gathering your registry. Please contact us
with the following information, and we will resolve the issue for
you:<p>" . mysql_error() . "</p>";
	exit();
}

while($row = mysql_fetch_array($result))
{
    $prodname = $row["prodName"];
	$prodprice = $row["prodPrice"];
	$pid = $row["pid"];
	$photo = $row["photo"];

	print "pn: $prodname";
	print "R: $row";

	if(!$prodname)
	{
		print "registry is empty.";
		print "pn(in): $prodname";
	}
//stuff
}
-------------------------

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



More information about the thelist mailing list