编码点火器Where_In操作员会返回任何结果



我正在使用Codeigniter通过将数组传递到模态中来查询结果列表。但返回结果始终为空。我已经检查并尝试了一些我在堆栈溢出上找到的方法,但没有一个有效。

例如。 数组 ( [0] => 12 [1] => 13 )

我的代码 :

<?php
ini_set('max_execution_time', 0);
ini_set('memory_limit','2048M');
defined('BASEPATH') OR exit('No direct script access allowed');
class Sms_model extends CI_Model
{
//Return Selected Customer ID
public function getCustomerInfo($data){
$ids = array();
foreach ($data['customerID'] as $id)
{
$ids[] = $id;
}
print_r($ids);
$this->db->select('Handphone');
$this->db->from('tblcustomer');
$this->db->where_in('CustomerID', $ids);
$query = $this->db->get();
if ($query->num_rows() == 1) {
return $query->result();
} 
else {
return false;
}
}
}

我在查询上做错了什么? 请指导我,谢谢

你的问题出在你的IF语句中,应该是>0而不是== 1。您也可以删除您的 foreach。

这样:

<?php
ini_set('max_execution_time', 0);
ini_set('memory_limit','2048M');
defined('BASEPATH') OR exit('No direct script access allowed');
class Sms_model extends CI_Model
{
//Return Selected Customer ID
public function getCustomerInfo($data){
$this->db->select('Handphone');
$this->db->from('tblcustomer');
$this->db->where_in('CustomerID', $data['customerID']);
$query = $this->db->get();
if ($query->num_rows() > 1) {
return $query->result();
} else {
return false;
}
}
}

问题出在$this->db对象调用中。您可以按照以下代码获得结果。检查数据库中是否存在列和表

<?php
ini_set('max_execution_time', 0);
ini_set('memory_limit','2048M');
defined('BASEPATH') OR exit('No direct script access allowed');
class Sms_model extends CI_Model
{
//Return Selected Customer ID
public function getCustomerInfo($data){

//print_r($ids);
//give value for $ids variable
$this->db->select('Handphone'); 
$this->db->where('CustomerID', $ids);
$query = $this->db->get('tblcustomer');
if ($query ->result_id->num_rows > 0) {
return $query->result_object();
} 
else {
return false;
}
}
}

最新更新