Jump to content

Recommended Posts

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?  ;D

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";

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>';
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.