Re: [PHP] testing for negative numbers
Okay, I'm an idiot. It *was* making it to the statement, but the row_id in the table matrix_structure_routes are actually positive numbers, so when it gets to that point I need to use the absolute value. The reason for using the negative and postive counterparts are to determine which type of directory it is (and therefore which table the meta information is stored in). Stupid me for not catching that first! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] testing for negative numbers
Is it possible that the value is actually " -2" (with the space)? Robert Samuel White wrote: Well, I just tried your test script and that works just as it should, so I must be having some other issue. But that still doesn't explain why I can print out the results of $row["dir_id"] and it shows it being -2, yet my script (as printed in the last email) never makes it to the correct conditional statement. Rasmus Lerdorf wrote: Please provide a complete test script. Are you perhaps not realizing that array indices along with all variables in PHP are case sensitive? $row["ID"] and $row["id"] are not the same thing. The trivial test of your example: $myArray["id"] = -2; if ($myArray["id"] < 0) echo "Negative"; else echo "Positive"; Prints "Negative" as expected. -Rasmus On Thu, 6 Feb 2003, Robert Samuel White wrote: I realize this should be about the simplest thing in the world to do, but for this reason or that it's not working... I'm using PHP version 4.2.3 Whether I have a negative number in an array, for example: $myArray["ID"] = -2 Or the number comes from the database, for example: $row["id"] = -2 I cannot get this simple operation to work: if ($row["id"] < 0) Instead, positive or negative, it seems to think this expression is always true: if ($row["id"] > 0) It's like it takes the absolute value of the number (whether the number is 2 or -2, it thinks it is 2) I've tried many things, including type casting using (int) in front of the expression. Nothing has worked. Any ideas why in the world this is happening? Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- The above message is encrypted with double rot13 encoding. Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] testing for negative numbers
Well, I just tried your test script and that works just as it should, so I must be having some other issue. But that still doesn't explain why I can print out the results of $row["dir_id"] and it shows it being -2, yet my script (as printed in the last email) never makes it to the correct conditional statement. Rasmus Lerdorf wrote: Please provide a complete test script. Are you perhaps not realizing that array indices along with all variables in PHP are case sensitive? $row["ID"] and $row["id"] are not the same thing. The trivial test of your example: $myArray["id"] = -2; if ($myArray["id"] < 0) echo "Negative"; else echo "Positive"; Prints "Negative" as expected. -Rasmus On Thu, 6 Feb 2003, Robert Samuel White wrote: I realize this should be about the simplest thing in the world to do, but for this reason or that it's not working... I'm using PHP version 4.2.3 Whether I have a negative number in an array, for example: $myArray["ID"] = -2 Or the number comes from the database, for example: $row["id"] = -2 I cannot get this simple operation to work: if ($row["id"] < 0) Instead, positive or negative, it seems to think this expression is always true: if ($row["id"] > 0) It's like it takes the absolute value of the number (whether the number is 2 or -2, it thinks it is 2) I've tried many things, including type casting using (int) in front of the expression. Nothing has worked. Any ideas why in the world this is happening? Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] testing for negative numbers
Hi Rasmus: Yes, I'm totally aware of case sensitivity...and basically the script you wrote here is exactly what I'm trying to doing. This is a problem I've been having with several scripts...always when the number is negative. I've also echoed my variables just to make sure they are in fact negative numbers. This is an odd thing I've been dealing with for a while now. This only happens when the value is negative. But anyway, here's the part of the script I'm encountering the problem at: $result = $Database->Query("SELECT * FROM ".DBT__MATRIX_STRUCTURE_CONTENT." WHERE content_id = '".$tmpParentId."'"); while ($row = $Database->FetchArray($result)) { $tmpArray[$tmpCount]["ID-PARENT"] = $row["parent_id"]; $tmpArray[$tmpCount]["ID-DIR"]= $row["dir_id"]; $tmpArray[$tmpCount]["TYPE"] = $row["content_type"]; $tmpArray[$tmpCount]["FILE"] = $row["content_file"]; $tmpArray[$tmpCount]["TITLE"] = $row["content_title"]; $tmpArray[$tmpCount]["VERSION"] = $row["content_version"]; if ($row["dir_id"] > 0) { $resultc = $Database->Query("SELECT * FROM ".DBT__MATRIX_STRUCTURE_DIR." WHERE dir_id = '".$row["dir_id"]."'"); while ($rowc = $Database->FetchArray($resultc)) { $tmpArray[$tmpCount]["PATH"] = $rowc["dir_path"]; } $Database->FreeResult($resultc); } if ((int)$row["dir_id"] < 0) { $resultc = $Database->Query("SELECT * FROM ".DBT__MATRIX_STRUCTURE_ROUTES." WHERE dir_id = '".$row["dir_id"]."'"); while ($rowc = $Database->FetchArray($resultc)) { $tmpArray[$tmpCount]["ALIAS"] = $rowc["dir_alias"]; $tmpArray[$tmpCount]["PATH"] = $rowc["dir_path"]; echo "xxx"; exit(); } $Database->FreeResult($resultc); } Rasmus Lerdorf wrote: Please provide a complete test script. Are you perhaps not realizing that array indices along with all variables in PHP are case sensitive? $row["ID"] and $row["id"] are not the same thing. The trivial test of your example: $myArray["id"] = -2; if ($myArray["id"] < 0) echo "Negative"; else echo "Positive"; Prints "Negative" as expected. -Rasmus On Thu, 6 Feb 2003, Robert Samuel White wrote: I realize this should be about the simplest thing in the world to do, but for this reason or that it's not working... I'm using PHP version 4.2.3 Whether I have a negative number in an array, for example: $myArray["ID"] = -2 Or the number comes from the database, for example: $row["id"] = -2 I cannot get this simple operation to work: if ($row["id"] < 0) Instead, positive or negative, it seems to think this expression is always true: if ($row["id"] > 0) It's like it takes the absolute value of the number (whether the number is 2 or -2, it thinks it is 2) I've tried many things, including type casting using (int) in front of the expression. Nothing has worked. Any ideas why in the world this is happening? Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] testing for negative numbers
Please provide a complete test script. Are you perhaps not realizing that array indices along with all variables in PHP are case sensitive? $row["ID"] and $row["id"] are not the same thing. The trivial test of your example: $myArray["id"] = -2; if ($myArray["id"] < 0) echo "Negative"; else echo "Positive"; Prints "Negative" as expected. -Rasmus On Thu, 6 Feb 2003, Robert Samuel White wrote: > I realize this should be about the simplest thing in the world to do, > but for this reason or that it's not working... > > I'm using PHP version 4.2.3 > > Whether I have a negative number in an array, for example: > > $myArray["ID"] = -2 > > Or the number comes from the database, for example: > > $row["id"] = -2 > > I cannot get this simple operation to work: > > if ($row["id"] < 0) > > Instead, positive or negative, it seems to think this expression is > always true: > > if ($row["id"] > 0) > > It's like it takes the absolute value of the number (whether the number > is 2 or -2, it thinks it is 2) > > I've tried many things, including type casting using (int) in front of > the expression. > > Nothing has worked. > > Any ideas why in the world this is happening? Thanks. > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] testing for negative numbers
I realize this should be about the simplest thing in the world to do, but for this reason or that it's not working... I'm using PHP version 4.2.3 Whether I have a negative number in an array, for example: $myArray["ID"] = -2 Or the number comes from the database, for example: $row["id"] = -2 I cannot get this simple operation to work: if ($row["id"] < 0) Instead, positive or negative, it seems to think this expression is always true: if ($row["id"] > 0) It's like it takes the absolute value of the number (whether the number is 2 or -2, it thinks it is 2) I've tried many things, including type casting using (int) in front of the expression. Nothing has worked. Any ideas why in the world this is happening? Thanks. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php