2

使用html FORMlet's convert $corein 100and $mhzin 1000
emagand koyosare table rows
So if $coreis set $parameters['emag'] = "$core";is emag=100else it is null
ANDand WHEREare dinamicly set to appear,所以问题是我收集了变量的所有数据$parameters[]foreach()它们。
使用我的代码,我得到了确切$core的信息。这是代码:

if (!empty($core)) {
$parameters['emag'] = "$core";

}
if (!empty($mhz)) {
$parameters['koyos'] = $mhz;
  }

$sql = "SELECT * FROM $tbl_name WHERE 1=1 ";
if (!empty($parameters)) {
foreach ($parameters as $k => $v) {
    $sql .= " AND " . $k . "='" . $v . "'";
}
  }
$sql .= " ORDER BY emag, performanta_cpu_core DESC, performanta_cpu DESC LIMIT $start, $limit";

结果只是带有 的行,emag=100但我需要所有数字都等于或小于100100

4

2 回答 2

2

根据您提供的数据,您的查询条件是:

WHERE 1=1 AND emag = '100' AND koyos = '1000'

所以显然只会显示emag=的行100。如果要显示所有这些内容,请100更改=<=表名称为emag

foreach ($parameters as $k => $v) {

    if ($k == 'emag')
    {
        $sql .= " AND " . $k . "<='" . $v . "'";
    }

    else
    {
        $sql .= " AND " . $k . "='" . $v . "'";
    }

}
于 2013-03-11T22:39:15.403 回答
1

试试这个:

foreach ($parameters as $k => $v) {

    if ($k == 'emag') {
        $sql .= " AND " . $k . "<='" . $v . "'";
        continue;
    }

    $sql .= " AND " . $k . "='" . $v . "'";
}
于 2013-03-11T22:38:36.707 回答