Forum Moderators: coopster
This will probably appear quite basic, however I am in need of help.
I have a SQL database with an appropriate table. (as shown below)
-- Table structure for table `costlimits`
--
CREATE TABLE IF NOT EXISTS `costlimits` (
`limID` tinyint(3) unsigned NOT NULL,
`limMin` smallint(5) unsigned DEFAULT NULL,
`limMax` smallint(5) unsigned DEFAULT NULL,
`limCost` decimal(3,2) unsigned DEFAULT NULL,
PRIMARY KEY (`limID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
I want to be able to take a number submitted in a form field, and compare the value of that field to the limMin and limMax entries in order to retrieve the appropriate value from limCost. So simply, if:
x is between limMin and limMax return limCost
Hope that explains it,
any help would be greatly appreciated.
Thanks
(for example)
<input type="text" name="some-value" value="17">
limID limMin limMax limCost
1.....0......5......1
2.....5......10.....3
3.....10.....15.....7
4.....15.....20.....9
5.....20.....25.....12
$input = dont_forget_to_cleanse($_POST['some-value']);
$select = "select limCost from costlimits where limMin <= '$input' and limMax > '$input'";
The above should return 9. Note you only want one of these <= or >= (less than/greater than OR equal to.) Otherwise it would hook both rows 3 and 4 if the input is, say, 15.