giba Posted May 18, 2008 Share Posted May 18, 2008 HI there bodys! I am trying to make a search that compare two values from a DECIMAL field in the database, however, I am running into this problem: the query: $_query = "SELECT SQL_CALC_FOUND_ROWS * FROM products WHERE category LIKE _utf8 '%category%' COLLATE utf8_unicode_ci AND price BETWEEN '".$_POST[lessThan]."' AND '".$_POST[greaterThan]."'"; I have an array of values for dynamicly generate the option like this: $valuesForGreater = array(60000.00, 70000.00, ... etc ...) And the HTML generates this value="6000000", that is, he takes away the decimal value, I've tried to make this: $valuesForGreater = array(6000000, 7000000, ... etc ...) AND this $valuesForGreater = array('6000000', '7000000', ... etc ...) and nothing seems to work if I sent this datas to database the query doesn't return anything, and if I pretty do the following fixing the values in the query it works fine: $_query = "SELECT SQL_CALC_FOUND_ROWS * FROM products WHERE category LIKE _utf8 '%category%' COLLATE utf8_unicode_ci AND price BETWEEN '50000.00' AND '100000.00'"; The last try, was to settype for the option value: $min= settype($_POST[lessThan],"float"); $max = settype($_POST[greaterThan],"float"); What is that with HTML? Must I shoot it, or kick PHP? Quote Link to comment https://forums.phpfreaks.com/topic/106193-option-value-problems-when-inserting-into-mysql/ Share on other sites More sharing options...
MadTechie Posted May 18, 2008 Share Posted May 18, 2008 try this $less = (float)$_POST['lessThan']; $most = (float)$_POST['greaterThan']; $_query = "SELECT SQL_CALC_FOUND_ROWS,* FROM products WHERE category LIKE '%category%' AND price BETWEEN $less AND $most COLLATE utf8_unicode_ci"; Quote Link to comment https://forums.phpfreaks.com/topic/106193-option-value-problems-when-inserting-into-mysql/#findComment-544309 Share on other sites More sharing options...
giba Posted May 18, 2008 Author Share Posted May 18, 2008 Well, it still doesn't work Quote Link to comment https://forums.phpfreaks.com/topic/106193-option-value-problems-when-inserting-into-mysql/#findComment-544328 Share on other sites More sharing options...
Barand Posted May 18, 2008 Share Posted May 18, 2008 try <?php $valuesForLesser = array('10000.00', '20000.00', '30000.00', '40000.00'); $valuesForGreater = array('60000.00', '70000.00', '80000.00', '90000.00'); if (isset($_POST['btnSubmit'])) { $_query = "SELECT SQL_CALC_FOUND_ROWS * FROM products WHERE category LIKE _utf8 '%category%' COLLATE utf8_unicode_ci AND price BETWEEN '".$_POST[lessThan]."' AND '".$_POST[greaterThan]."'"; echo $_query; } echo '<form method="post""> Low value <SELECT name="lessThan">'; foreach ($valuesForLesser as $val) { echo "<option value='$val'> $val</option>"; } echo '</select><br/>'; echo 'High value <SELECT name="greaterThan">'; foreach ($valuesForGreater as $val) { echo "<option value='$val'> $val</option>"; } echo '</select><br/>'; echo '<input type="submit" name="btnSubmit" value="Submit"> </form>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/106193-option-value-problems-when-inserting-into-mysql/#findComment-544336 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.