elseif misfiring

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
bnw
Forum Newbie
Posts: 3
Joined: Fri Jul 02, 2010 4:50 pm

elseif misfiring

Post by bnw »

I'm another noob that hacked together some code and it stopped working :(

All my other conditionals were working until I got to this one.

This factor ($searoffice == "NULL") is being ignored i.e. the page is running the $sql6 function when $searoffice is not NULL.

Does anything jump out as being wrong? When I echo $searoffice it shows correctly. Thanks.

Code: Select all

elseif (($searoffice == "NULL")  && ($searcounty != "*") && ($searcounty != "NULL") && ($seartrans == "NULL")) 
{
	$sql6= "
		select countyname, count(orderkey) AS Expr1
		from tblorder
		where countyname = '$searcounty'
		AND (OrderDateTime between '$searstdate' AND '$searenddate')
		group by countyname";

	$result = odbc_exec($sqlconnect, $sql6);
		while ($row = odbc_fetch_array($result)) {
		   echo $row["countyname"], "\n";
		   echo $row["Expr1"], "<br>";

}
}
elseif (($searoffice != "NULL") && ($searoffice != "*") && ($searcounty != "*") && ($searcounty != "NULL") && ($seartrans == "NULL")) 

{

	$sql7= "
		select titleunitname, tblorder.countyname, count(orderkey) AS Expr1
		from tblorder
		inner join qrytitleunits on tblorder.titleunitnum = qrytitleunits.titleunitnum
		where tblorder.countyname = '$searcounty'
		AND titleunitname = '$searoffice'
		AND (OrderDateTime between '$searstdate' AND '$searenddate')
		group by titleunitname,tblorder.countyname";

	$result = odbc_exec($sqlconnect, $sql7);
		while ($row = odbc_fetch_array($result)) {
		   echo $row["titleunitname"], "\n";
		   echo $row["countyname"], "\n";
		   echo $row["Expr1"], "<br>";

}

}

User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: elseif misfiring

Post by Jonah Bron »

First, what do you mean by "stopped working"? Either it never worked, somebody changed it, or the server upgraded their software (which can probably be ruled out in this case).

Are you sure you want the null in quotes? Or could it be lowercase? "NULL" and null do not mean the same thing (but you may already know that).
bnw
Forum Newbie
Posts: 3
Joined: Fri Jul 02, 2010 4:50 pm

Re: elseif misfiring

Post by bnw »

Hi - I meant it stopped working as in the code before was using conditionals correctly until I added that part.

It still functions but it isn't responding to the conditionals "correctly".

I tried to use actual NULL values like ' ' single quotes with no value inside but had trouble getting it to work, so I just used the actual word NULL.

I am thinking the problem may be that I didn't use any parenthesis in the conditionals to set the order.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: elseif misfiring

Post by califdon »

NULL is not the same as an empty string (either '' or ""). If you are really testing for the NULL condition, do not use any quotation marks. NULL is recognized as a global constant. See http://php.net/manual/en/language.types.null.php
bnw
Forum Newbie
Posts: 3
Joined: Fri Jul 02, 2010 4:50 pm

Re: elseif misfiring

Post by bnw »

Thanks. I had an equals sign wrong in another part of the code which was throwing it off. Fixing the NULLs is probably wise though.
Post Reply