dongzj2015 2013-04-04 08:40
浏览 164

错误:SQLSTATE [42S22]:找不到列:1054 where子句中的未知列

Having a problem with this here function. It's supposed to return a json string of data gathered using the sql call below. The problem is that I'm getting an error code "500" when accessing the page through my server (for example - localhost/app/API/states/Alabama/1/10.json). The odd thing is that the data is showing up as expected using both .json and without the appending .json. Controllers and Models are set up just fine as far as I can tell, yet the the error code remains:

{"code":500,"url":"/VOI2/API/states/Alabama/2/10.json","name":"SQLSTATE[42S22]: >Column not found: 1054 Unknown column 'states' in 'where >clause'","error":{"errorInfo":["42S22",1054,"Unknown column 'states' in 'where >clause'"]

public function index($stateName, $page, $limit = 10, $user = null) {
$this->State->recursive = 0;
$limit;
$set_limit = $page * $limit - ($limit);
$states = $this->State->query("SELECT * 
FROM states, issues
WHERE stateName =  '" . $stateName ."'
AND issues.state_id = states.id LIMIT " .  $set_limit . "," . $limit)       
$this->set('states', $this->paginate($states));
$this->set('_serialize', array('states'));  
}

Issues is another table with model/controller. I wanted to have the urls setup in a meaningful manner is why I chose to separate states from issues. Thanks all for your help.

  • 写回答

2条回答 默认 最新

  • douci2022 2013-04-04 09:17
    关注

    It is not allowed to use aliases in WHERE clause. See Problems with Column Aliases and Can you use an alias in the WHERE clause in mysql?

    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大