hi i've been trying to figure out whats wrong with my code for hours, with no success, ive tried converting the types
using floatval() and doubleva(), with no improvement.
The script gathers the weight and the ID of a turkey, and every row retrived it checks that ID hasn't already been used by running it through an array of ID's that have been used. All this works fine. Its when i have a loop that is used to print part of a drop down menu that displays Turkey ID's that match the weights as close as possible in the correct order.
here is an extract from the script.
for($a=0; $a<=5; $a= ($a + 0.005)) {
$resultad = mysql_query("SELECT TurkeyID, Weight FROM turkey;");
if (!$resultad) {echo("<b>Error performing query: " . mysql_error() . "</b>"); exit();}
while ($columnad = mysql_fetch_array($resultad)) {
foreach ($list_of_assigned_turkey_ids as $list) {
if($list==$columnad[0]) {$deny_turkey_id=true;}
}
if($deny_turkey_id!=true) {
//echo("1.loop $a does " .$columnad[1] ." == " . ($request_weight + $a) ."\n");
//echo("2.loop $a does " .$columnad[1] ." == " . ($request_weight - $a) ."\n");
if($columnad[1]==($request_weight + $a)) {echo("<option value=\"" . $columnad[0] ."\">Turkey ID:" . $columnad[0] .", Weight: " . $columnad[1] ."Kg (+" .$a .")</option>\n");}
if($columnad[1]==($request_weight - $a)) {echo("<option value=\"" . $columnad[0] ."\">Turkey ID:" . $columnad[0] .", Weight: " . $columnad[1] ."Kg (-" .$a .")</option>\n");}
;}
//reset variable for checking next TurkeyID
$deny_turkey_id = false;
//end while
}
//end main gen for
}
i used the the echo("1.loop $a does " .$columnad[1] ." == " . ($request_weight + $a) ."\n"); to moniter how the script progresses and when say , the $request weight =5.0
when $a=0.955, when
$columnad[1] = 5.995
$request_weight + $a = 5.955
when they are compared, using the if statement, it returns false, but this extract from the tested php script shows 5.995 == 5.995 ,yet the if statement says they are not equal as nothing is outputed.
1.loop 0.995 does 5.995 == 5.995
2.lopp 0.995 does 5.995 == 4.005
when $a=0.005 it works as it should but once past 0.500 it doesn't seem 2 work at all.
can any one help me?