RE: getting a number range from user input.. (weight)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I don't understand why you have the 'Weight_kg = "6"' clause in your WHERE
statement?

Aren't you attempting to return one of the zone values depending on a value
that falls between range and weight_kg?

Let's say, for example, that the value you're searching for is .45. The
following statement would correctly return the record below:

SELECT * FROM rates_dhl WHERE .45 BETWEEN range AND Weight_KG

In your PHP code, you'd probably use a variable when building the SQL
statement.

Something like:

<?
$srchvar = .45;
$sql = "SELECT * FROM rates_dhl WHERE $srchvar BETWEEN range AND Weight_KG";

// Retrieve recordset from db as normal
?>

This is assuming range and Weight_KG are both decimals in your db, rather
than VARCHARS etc.

It may be that I've misunderstood what you're attempting to do.

Much warmth,

Murray
http://www.planetthoughtful.org
Building a thoughtful planet,
One quirky comment at a time.


> -----Original Message-----
> From: Louie Miranda [mailto:lmiranda@xxxxxxxxx]
> Sent: Friday, 5 November 2004 4:06 PM
> To: Murray @ PlanetThoughtful; php-general@xxxxxxxxxxxxx
> Subject: Re:  getting a number range from user input.. (weight)
> 
> I have this on my db.
> 
> mysql> select * from rates_dhl where weight_kg = "6" between range and
> Weight_KG;
> +----+-------+-----------+--------+--------+--------+--------+--------+---
> -----+--------+--------+
> | id | range | Weight_KG | Zone_A | Zone_B | Zone_C | Zone_D | Zone_E
> | Zone_F | Zone_G | Zone_H |
> +----+-------+-----------+--------+--------+--------+--------+--------+---
> -----+--------+--------+
> |  1 | .000  | .5        | 9.45   | 12.29  | 14.18  | 15.12  | 16.59
> | 18.48  | 21.32  | 23.63  |
> +----+-------+-----------+--------+--------+--------+--------+--------+---
> -----+--------+--------+
> 1 row in set (0.00 sec)
> 
> When i did try the between, even when i try to change the weight_kg to
> any number, it only display the first entry.
> 
> 
> On Fri, 5 Nov 2004 15:52:16 +1000, Murray @ PlanetThoughtful
> <lists@xxxxxxxxxxxxxxxxxxxx> wrote:
> >
> >
> >
> > > OK, here is what it should do.
> > >
> > > I have a fixed range of weights from .5 to 20.0 Kg (kilogram) and for
> > > each weight it has a succeeding value, i cannot jump or just round off
> > > the numbers. So i need a range detector to do it.
> > >
> > > Because for each of the item below:
> > >
> > > > weight   value
> > > > .5            9.45
> > > > 1.0         10.71
> > > > 1.5         11.97
> > > > 2.0         13.23
> > >
> > > I must get the exact value, so let say for example. I have 1.3 it
> > > should fall under 1.5 the idea i had was to do this, so i can detect
> > > where the number should fall..
> >
> > Put the weight ranges in a MySQL table and use the BETWEEN operator to
> > retrieve the appropriate weight.
> >
> > Something like:
> >
> > fromweight, toweight, value
> > 0,0.5,9.45
> > 0.501,1.0,10.71
> > 1.001,1.5,11.97
> >
> > Then, the following SQL statement will pull the appropriate value:
> >
> > SELECT value FROM weights WHERE 1.3 BETWEEN fromweight AND toweight
> >
> > Much warmth,
> >
> > Murray
> > http://www.planetthoughtful.org
> > Building a thoughtful planet,
> > One quirky comment at a time.
> >
> > --
> >
> >
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> 
> 
> --
> Louie Miranda
> http://www.axishift.com
> 
> --
> 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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux