在两个数字之间搜索(百分比)


Searching between two numbers(percentage)

我有这个代码;

<?php
$username = "root";
$password = "Toom13371!";
$lowfreq = $_POST['Lowfreq']; # User-Supplied Data.             I'm A
$highfreq = $_POST['Highfreq']; # User-Supplied Data.        Placeholder yo.
$construction = $_POST['construction_type']; # User-Supplied Data.   Still holding
$connector = $_POST['connector_type']; # User-Supplied Data.                that place.
try {
    $dbh = new PDO("mysql:host=127.0.0.1;dbname=filters", $username, $password);
} catch(PDOException $e) {
    echo $e->getMessage();
}

//print
//echo $highfreq;
//echo $lowfreq;
//echo $connector;
//echo $construction; #tests
$condition = array(); #sets condition as array
$strcond = ""; #sets $strcond as "empty"
if (!empty($lowfreq)) {
    $condition[] = " start_passband = $lowfreq";
}
if (!empty($highfreq)) {
    $condition[] = " stop_passband = $highfreq";
}
if (!empty($construction)) {
    $condition[] = " construction_type = '$construction'";
}
if (!empty($connector)) {
    $condition[] = " connector_type = '$connector'";
}
if (!empty($condition)) {
$tempx = implode(' AND', $condition);
$tempy = " WHERE " . $tempx;
print $tempx;
unset($condition); #clears the array $condition
$condition= array(); 
$strcond = $tempy;
//print $strcond;
    //$condition .= " ".implode(' AND', $condition);
    }
    // Select some data
$sth = $dbh->prepare("SELECT id, type_code, connector_type, construction_type, start_passband,     stop_passband, lower_stopband_start, lower_stopband_stop, upper_stopband_start, upper_stopband_stop      FROM filter_bandpass $strcond");
// Execute the query, replacing the placeholders with their true value
$sth->execute(array());

我想做的是使用$lowfreq/$highreq,然后在其+/-20%之间搜索,以返回所有值,其中$lowfreq+/-20%,然后$highfreq+/-20%。

非常感谢您的帮助。

如果您询问如何获得百分比:

$lowfreqlow = $lowfreq * 0.8;
$lowfreqhigh = $lowfreq * 1.2;
$highfreqlow = $highfreq * 0.8;
$highfreqhigh = $highfreq * 1.2;

然后是新SQL查询的类似"... WHERE lowfreqcolumn BETWEEN ".$lowfreqlow." AND ".$lowfreqhigh." AND highfreqcolumn BETWEEN ".$lowfreqlow." AND ".$lowfreqhigh的内容。