duan4523 2015-01-20 13:39
浏览 680

“字段列表”中的未知列选择

I've looked at the other 15 or so answers related to this and haven't come up with an answer that works. Here's the code responsible:

function count_distinct($table, $field, $from, $match, $other='Other'){
    try{
        $ret = array();
        $query = 'SELECT '.$table.'.'.$field.', COUNT(*) AS num FROM  '.$from;
        $query .= ($match) ? ' WHERE '.$match : '';
        $query .= ' GROUP BY `'.$table.'`.`'.$field.'`';
        $q = mysqli_query($this->con, $query);
        if (!$q) {
            throw new Exception('Error executing query ' . $query . ' ' . mysqli_error($this->con));
        } else {
            ...
        }
        return $ret;
    }
    catch(Exception $e){...     }
}

I've removed some of the processing code which seems to work fine. The inputs for this function are code-generated, not client/user generated, and are free from white space or symbols.

I'm getting this error:

Error executing query SELECT interventions.iTYPE, COUNT(*) AS num
                  FROM  interventions JOIN INC ON INC.form_id = interventions.form_id JOIN FORMS ON INC.form_id=FORMS.form_id WHERE `interventions`.`iCAT` = "IV/IO" AND INC.`Pt.AgeRange` <> "Manikin/Lab" AND FORMS.course_id="15" GROUP BY `interventions`.`iTYPE` Unknown column 'interventions.iTYPE' in 'field list'

The table config is this:

interventions
  form_id (int (10))
  iCAT (varchar(20))
  iTYPE (varchar(20))
  Result (tinyint(1))

INC
  form_id (int(10))
  Pt.AgeRange (varchar(20))

FORMS
  form_id (int(10))
  course_id (int(20))

etc.

The crazy part is that if I copy/paste the query printed in the error message and run it in Sequel Pro it works fine, error free, and prints the result without a problem.

I'm at my wits end—I've tried restarting the server, changing the order of the field list, removing the GROUP BY clause, adding back ticks, removing them...I'm out of ideas.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
    • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
    • ¥15 如何处理复杂数据表格的除法运算
    • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
    • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
    • ¥200 uniapp长期运行卡死问题解决
    • ¥15 latex怎么处理论文引理引用参考文献
    • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
    • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
    • ¥15 乘性高斯噪声在深度学习网络中的应用