Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/63.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我的codeigniter查询正确吗?_Php_Mysql_Sql_Codeigniter - Fatal编程技术网

Php 我的codeigniter查询正确吗?

Php 我的codeigniter查询正确吗?,php,mysql,sql,codeigniter,Php,Mysql,Sql,Codeigniter,我的查询中的“where”语句不起作用 $this->db->select(array("pr_id","id","unit_id","item_description","quantity","unit_cost","total_cost")); $this->db->where('id','1'); $this->db->from("tblitem"); select和from语句非常好。我的数据表正在出现。但它忽略了where语句。我不知道我的说法是否

我的查询中的“where”语句不起作用

$this->db->select(array("pr_id","id","unit_id","item_description","quantity","unit_cost","total_cost"));
$this->db->where('id','1');
$this->db->from("tblitem");

select和from语句非常好。我的数据表正在出现。但它忽略了where语句。我不知道我的说法是否正确。请帮帮我,谢谢。

我认为这是正确的方法

    $this->db->select("pr_id","id","unit_id","item_description","quantity","unit_cost","total_cost");
$this->db->where('id',1);
$this->db->from("tblitem");

从选择中删除数组。您可以通过用逗号分隔表列来选择表列

并且还替换

$this->db->where('id','1');

注意:如果
id
字段为int,则删除引号

也许这会有帮助。

试试这个

$this->db->select("pr_id,id,unit_id,item_description,quantity,unit_cost,total_cost");
$this->db->get_Where('tblitem', array('id'=>'1'));

echo $this->db->result()

希望获得此帮助

删除Select查询的数组并删除id(int)的引号


请从select语句中删除数组,以便查询如下所示:

$this->db->select(`pr_id`,`id`,`unit_id`,`item_description`,`quantity`,`unit_cost`,`total_cost`);
$this->db->where('id',1);
$this->db->from('tblitem');

$result=$this->db->get();
然后,如果要访问单行,请使用:

$row = $result->row();
或者,如果查询结果为纯数组,或者未找到结果时为空数组,请使用:

$result->result_array().
例如:

foreach ($result->result_array() as $row)
{
        echo $row['title'];
        echo $row['name'];
        echo $row['body'];
}

不从选择中删除数组()。。。为什么在select中使用数组?您的查询很好。。。你怎么知道你的说法不对?你应该多解释一下。。。(@ash在这里看一下-你也可以传递一个数组)用引号换行,在int字段中搜索就可以了。没有问题3投票给一个完全错误的答案,这个网站变得越来越奇怪。。。你能解释一下为什么这能解决问题,让其他人能从你的答案中学习吗?你能解释一下为什么这能解决问题,让其他人能从你的答案中学习吗?
$result->result_array().
foreach ($result->result_array() as $row)
{
        echo $row['title'];
        echo $row['name'];
        echo $row['body'];
}