Hi,
I'm having some trouble with comparing decimal values.
For example, I have the following table:
name value1 value2
foo -1.25 1.5
bar 0.05 0.07
baz -1.01 0.03
I have a submit form from which the user can make a selection based on
the criteria from "value1" and "value2." For example, let's say the
user wants to see all of the rows where "value1" is less than 3 and
"value2" is less than 0.06.
He/she would enter 1 and 0.06 in the corresponding boxes and click
submit. Only row "baz" fits the criteria, so the output would be:
baz -1.01 0.03
The following is the selected portion of code:
<FORM action="http://myHost/myPage.php" method="post">
<P>
value1 < <INPUT type="text" name="value1" size =
"10">
value2 < <INPUT type="text" name="value2" size = "10"><BR>
<INPUT type="submit" value="SUBMIT">
</P>
</FORM>
<?php
if ($_REQUEST[submit] = 'SUBMIT'){
$result = mysql_query("SELECT * FROM MyTable WHERE value1 < '.
$_REQUEST[value1] .' AND value2 $_REQUEST[value2]");
while($row = mysql_fetch_array($result))
{
echo "$row[0] $row[1] $row[2] <br />";
}
}
I have read that a possible solution is to use the absolute value
function,
ABS() on your values.. However, in this case I don't think that's
possible since my values contain negative decimal numbers.
Also, I have tried to change datatypes such as DECIMAL and FLOAT, but
still no luck.
Any suggestions would be much appreciated!!
Thanks,
Cam