dongyi1524 2013-03-11 22:26
浏览 3
已采纳

SQL Query使用PHP显示x和y之间的所有数字

Using an html FORM let's convert $core in 100 and $mhz in 1000
emag and koyos are table rows
So if $core is set $parameters['emag'] = "$core"; is emag=100else it is null
AND and WHERE are dinamically setted to appear, so the problem is that I collect all data of variables in $parameters[] and foreach() them.
With my code I am get exactly what $core is. This is the code:

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

And it is results just rows with emag=100, but I have need all numbers equals or little than 100 not just 100

  • 写回答

2条回答 默认 最新

  • du4010 2013-03-11 22:39
    关注

    Your query conditions, based on the data you've provided, are:

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

    And so obviously will only show rows where emag = 100. If you want to show all those up to 100 then change = to <= when the table name is emag:

    foreach ($parameters as $k => $v) {
    
        if ($k == 'emag')
        {
            $sql .= " AND " . $k . "<='" . $v . "'";
        }
    
        else
        {
            $sql .= " AND " . $k . "='" . $v . "'";
        }
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答