Page 1 of 1

elseif misfiring

Posted: Fri Jul 02, 2010 5:03 pm
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>";

}

}


Re: elseif misfiring

Posted: Fri Jul 02, 2010 5:46 pm
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).

Re: elseif misfiring

Posted: Sun Jul 04, 2010 3:24 pm
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.

Re: elseif misfiring

Posted: Sun Jul 04, 2010 6:35 pm
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

Re: elseif misfiring

Posted: Tue Jul 06, 2010 9:16 am
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.