简体   繁体   English

“ where子句”中的未知列“ $ id”

[英]Unknown column '$id' in 'where clause'

I am using codeigniter, I am displaying all the job vacancies on one page, each individual job post has a button to view more information about the current post. 我正在使用codeigniter,我将所有职位空缺显示在一页上,每个单独的职位都有一个按钮,可查看有关当前职位的更多信息。 when I try to pass the id variable for the individual post into the query I keep getting the error below. 当我尝试将单个帖子的id变量传递到查询中时,我不断收到以下错误。

Unknown column '$id' in 'where clause' “ where子句”中的未知列“ $ id”

query code 查询代码

function get_vacancie($id) {

$query = $this->db->query('SELECT vacancies_id,name, vacancie_desc, pay FROM vacancies where vacancies_id=$id');
return $query = $query->row();


}

Your query should look like this: 您的查询应如下所示:

$query = $this->db->query('SELECT vacancies_id,name, vacancie_desc, pay FROM vacancies WHERE vacancies_id=' . $id);

This should work! 这应该工作!

Strings in single quotes doesn't evalute PHP variables. 单引号中的字符串不会评估PHP变量。 Change single-quotes to double-quotes and it will do the job: 将单引号更改为双引号即可完成此工作:

$query = $this->db->query("SELECT vacancies_id,name, vacancie_desc, pay FROM vacancies where vacancies_id=$id");

Your mistake was single quote 你的错误是单引号

function get_vacancie($id) {
$query = $this->db->query("SELECT vacancies_id,name, vacancie_desc, pay FROM vacancies where vacancies_id=$id");
return $query = $query->row();
}

Try this code with double code 尝试此代码与双重代码

您也可以这样做:

$query = $this->db->query("SELECT vacancies_id,name, vacancie_desc, pay FROM vacancies WHERE vacancies_id={$id}");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM