Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rather unusual php problem, not sure what's wrong.

Status
Not open for further replies.

CHeighlund

Programmer
Jun 11, 2007
163
US
I have a php report page I'm working on that's giving me some problems. It's designed to be used on multiple systems; as far as I know, all of these systems are identical. On the system I did development on, the page displays information as needed. On the others, I don't get to see it unless I knock out a specific block of code. Thing is, the code in question doesn't relate to what I'm doing.

This page is designed to be used for two reports. They draw the same information, and they have almost the same format. Therefore, I figured that, since the two are also supposed to always be displayed together, it'd be a good idea to simply modify the original code so it had segments for report A and segments for report B.

Which path is followed is determined by a specific flag variable, $_90Plus. In report A, $_90Plus is supposed to be false; in report B, $_90Plus is supposed to be true.

As I mentioned above, when I'm running the program, I get what seems to me to be a rather strange error. Report B (remember, that's $_90Plus == true) doesn't run to completion if this segment of code, which has meaning only for report A, isn't commented out.
Code:
            if ($_90Plus == 'False')
            {
              $statnSQL = "****";
              $statnResult = @mysql_query($statnSQL) or die("could not complete station query");
              $row2 = @mysql_fetch_array($statnResult);
              $statnCnt = $row2["count(Stn_Seq)"];

              $statnSQL = "****";
              $statnResult = @mysql_query($statnSQL) or die("could not complete station query");
              $row2 = @mysql_fetch_array($statnResult);
              $statnCntChk = $row2["count(Stn_Seq)"];
            }
(SQL statements removed as it's business information and I don't want to risk it getting scattered around online.)

Other sections of the code that rely on the 'if ($_90Plus == 'False')' code being set seem to work correctly, only this one does not. And again, if I completely comment it out, I get my report B data correctly, but not my report A data, which does require this code.

Anybody have any ideas what might be causing this kind of problem?
 
this should answer your question
Code:
<?php
$a = false;
if ($a == 'False'){
	echo 'test 1: $a is false';
} else {
	echo 'test 1: $a is not false';
}
echo "<br/>";
if ($a == false){
	echo 'test 2: $a is false';
} else {
	echo 'test 2: $a is not false';
}
/* gives
test 1: $a is not false
test 2: $a is false
*/
?>

i suspect your problems will disappear if you remove the quotes around False. alternatively, if you really are using strings to denote boolean values then (i) stop and (ii) use the === comparison operator.
 
I thank you for your quick response. However, I attempted the fix you recommend on one of the systems which is not giving the data I am requesting, with no effect. I thank you for the reminder of proper style, and will do my best to continue in it in the future, but it does not appear to be responsible for my errors at this point; only the one entry (still) causes problems.
 
can you show us the code where $_90Plus gets set?
 
The report in question is one of a set of reports that can be selected from a php form. The following is the complete text of the selection statement that picks that particular pair of reports.

Code:
if ($reportselect == "IncompSites") {
        $_90Plus = False;
        include 'incomp_sites.php';
        $_90Plus = True;
        include 'incomp_sites.php';
}

I'm beginning to think that it might have been better to create a new report than attempt to modify the old one. And I recognize that I'm probably not following the best practices around.
 
the code above will ALWAYS result in $_90Plus being true. I suspect that this is not what you want.

should you not have an "else" clause somewhere?

Code:
if ($reportselect === "IncompSites") {
        $_90Plus = FALSE;
} else {
        $_90Plus = TRUE;
}
include 'incomp_sites.php';
 
The code above will result in both report forms appearing on the same page. First, set $_90Plus to false. Then, include the report. Next, set $_90Plus to true, then include the report a second time. Both reports are supposed to be run and presented at the same time, I apologize if I did not make this clear earlier.
 
ok. then there is nothing wrong with your conditional code.

on the first code segment, make the conditional
Code:
if ($_90Plus === FALSE)

for the rest of it my advice would be to change the die() calls to die(mysql_error()); it may well give you some better debugging advice.

on the sql calls - i'd recomment aliasing the count() expressions and then referring to the alias.
 
I do think your trying to access an undefined index in two of your arrays.

$statnCntChk = $row2["count(Stn_Seq)"];
$statnCnt = $row2["count(Stn_Seq)"];

I suspect you really want to do the following:
$statnCntChk = $row2[count(Stn_Seq)];
$statnCnt = $row2[count(Stn_Seq)];

Fixing one piece at a time will get you there. Try doing a little debugging yourself an see where your really going wrong.

I like to put echo statements at certain point in the program just to let me know I hit that point or entered that code block. Do like an echo "1<br />"; echo "2<br />"; and so on throught your code. Furthermore you can echo the value of each variable when it should change. This might let you visualize whats really going on and let know where your going wrong.
 
@solaris5

consider this query
Code:
select count(Stn_Seq) from table where Stn_Seq > 90

the value of the returned column might be 100. it's key in an associative array would be "count(Stn_Seq)". I take the view, therefore, that the OP was correct in his use of the array key
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top