473,386 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

decimal comparison

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">&nbsp;&nbsp;&nbsp;
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] &nbsp; $row[1] &nbsp; $row[2] &nbsp; <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
Jul 19 '05 #1
2 5132
Figured it out.
The following chunk is the problem:
if ($_REQUEST[submit] = 'SUBMIT'){
$result = mysql_query("SELECT * FROM MyTable WHERE value1 < '.
$_REQUEST[value1] .' AND value2 $_REQUEST[value2]");


It should look like this:

if ($_REQUEST[submit] == 'SUBMIT'){
$result = mysql_query("SELECT * FROM MikeYoung WHERE ZT2 < '".
$_REQUEST[zt2] ."' AND ZT6 < '". $_REQUEST[zt6] ."'");

Note the change to the actual syntax of the SELECT statement within
the mysql_query(). The extra "" needed to be added in the appropriate
spots. Watch that syntax! ;)
Jul 19 '05 #2
Figured it out.
The following chunk is the problem:
if ($_REQUEST[submit] = 'SUBMIT'){
$result = mysql_query("SELECT * FROM MyTable WHERE value1 < '.
$_REQUEST[value1] .' AND value2 $_REQUEST[value2]");


It should look like this:

if ($_REQUEST[submit] == 'SUBMIT'){
$result = mysql_query("SELECT * FROM MikeYoung WHERE ZT2 < '".
$_REQUEST[zt2] ."' AND ZT6 < '". $_REQUEST[zt6] ."'");

Note the change to the actual syntax of the SELECT statement within
the mysql_query(). The extra "" needed to be added in the appropriate
spots. Watch that syntax! ;)
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
4
by: Dean G | last post by:
I need to compare two values. one from a text field 'bid' and the other from a field in an sql server database 'maxbid'. The problem is the column in the database has decimal as its data type...
3
by: Typpo | last post by:
Hi, I have an ArrayList of decimals, and I want to figure out which two are the closest (least difference) from one another. I know I can loop through the decimals, but this is very tedious and...
28
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
4
by: Ronald S. Cook | last post by:
We're designing the data model for a project. The app will be in .NET, the database will be in SQL Server 2005. I'm a little confused on type conversion between the two and which I should...
1
by: =?Utf-8?B?R2F2?= | last post by:
Hi all, I'm trying to update an SQL database by allowing users to upload a csv file via webform. I then want to fill a datagrid to show what changes have been made. At first I tried using...
4
by: Yuan HOng | last post by:
Hi, It seems decimal object will always be larger than float in comparasion, which goes against common sense: False True It seems to me that rather than allowing this to happen,...
17
by: D'Arcy J.M. Cain | last post by:
I'm not sure I follow this logic. Can someone explain why float and integer can be compared with each other and decimal can be compared to integer but decimal can't be compared to float? True...
0
by: =?ISO-8859-1?Q?Gerhard_H=E4ring?= | last post by:
D'Arcy J.M. Cain wrote: I can give you the technical answer after reading the sources of the decimal module: you can only compare to Decimal what can be converted to Decimal. And that is int,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.