[英]How to pass multiple parameter to a function or query in codeigniter
What i want is to fetch all those customer's profile whose country in address is india. 我要获取的是地址在印度的所有这些客户的个人资料。
I am having two tables customers
and address
. 我有两个表
customers
和address
。 ' customers
' table have address_ID
and in address
table i am having the country_ID
. “
customers
”表具有address_ID
而在address
表中,我具有country_ID
。
I have tried so far is this : 到目前为止,我尝试过的是:
On ajax call i get this controller's function: 在ajax调用上,我得到此控制器的功能:
function listCustomerByCountry(){
if(isset($_REQUEST['id']) && $_REQUEST['id']!=null)
{ $id=$_REQUEST['id'];
//print_r($id);
$cid=$this->report_model->getAddressidByCountryid($id);
foreach($cid as $rs)
{
$addid = $rs['addressId'];
print_r($addid);
$result=$this->report_model->get_customer_by_addressId($addid);
print_r($result);
}
//var_dump($cid);
//die();
$result=$this->report_model->get_customer_by_addressId($addid);
print_r($result);
}else
{
$result=$this->report_model->get_customer_by_addressId();
}
echo'<table class="table table-striped table-bordered table-hover dataTables-example" ><thead><tr><th>Id</th><th>Customer Name</th><th>Customer Address</th><th>Phone Number</th><th>Email</th><th>Plan Type</th><th>Application Status</th><th>View</th><th>Edit</th><th>Ticket</th></tr></thead><tbody>';
foreach ($result as $customers){
$status = unserialize (STATUS);
$statusDb = $customers['applicationStatus'];
$val='<tr class="gradeX"><td>'.$customers['customerVisibleId'].'</td>';
$val.='<td><a href="'.base_url("customer/profile/".$customers['customerId']).'">'.$customers['customerName'].'</td>';
$val.='<td>'.$customers['customerAddress'].'</td>';
$val.='<td>'.$customers['phnoMobile'].'</td>';
$val.='<td>'.$customers['email1' ].'</td>';
$val.='<td>'.$customers['planId'].'</td>';
$val.='<td>'.($status[$statusDb]).'</td>';
$val.='<td><a href="'. base_url("customer/view/".$customers['customerId']).'"><i class="fa fa-eye"></i></a></td>';
$val.='<td><a href="'.base_url("customer/edit/".$customers['customerId']).'"><img src="'.base_url().'assets/img/edit.png" width="16" height="16" /></a></td>';
$val.='<td><a href="'.base_url("customer/ticketid/".$customers['customerId']).'"><i class="fa fa-text-width"></i></a></td>';
$val.= '</tr>';
echo $val;
}
echo '</tbody><tfoot></tfoot></table>';
die();
} }
and in model i am fetching country_ID
from address
table based on the dropdown selection and then the customer's profile data from customers
table based on the address_ID
. 在模型中,我根据下拉选择从
address
表中获取country_ID
,然后根据address_ID
从customers
表中获取客户的个人资料数据。
Model: 模型:
public function getAddressidByCountryid($id){
$query = $this->db->get_where('address', array('country' => $id));
$row=$query->result_array();
return $row;
}
public function get_customer_by_addressId($id)
{
$query = $this->db->get_where('customers', array('customerAddress' => $id));
print_r($id);
die();
return $query->result_array();
}
Problem is i am only getting the last address_ID and last customerID when fetch from the second function get_customer_by_addressId
问题是从第二个函数
get_customer_by_addressId
获取时,我仅获取最后的address_ID和最后的customerID
What wrong i am doing? 我在做什么错? do the controller function not passing all the addres_IDs?
控制器功能没有传递所有的addres_ID吗?
Table Structure 表结构
Table Customers
+----+-------+-----------+
| id | name | addressID |
+----+-------+-----------+
| 1 | demo | 12 |
| 2 | test | 13 |
| 3 | demo1 | 14 |
| 4 | demo2 | 15 |
+----+-------+-----------+
Table address:
+-----------+-----------+------------------+-----+
| addressID | countryID | stateID | cityID |
+-----------+-----------+------------------+-----+
| 12 | 1 | 1 | 1 |
| 13 | 1 | 1 | 1 |
| 14 | 1 | 1 | 1 |
| 15 | 2 | 2 | 2 |
+-----------+-----------+------------------+-----+
Result Table 结果表
+----+-------+-----------+
| id | name | addressID |
+----+-------+-----------+
| 1 | demo | 12 |
| 2 | test | 13 |
| 3 | demo1 | 14 |
+----+-------+-----------+
Now i want all the customr's data whose countryID is 1 现在我想要countryID为1的所有客户数据
So I'm updating your code as below. 因此,我正在如下更新您的代码。
Controller 调节器
$result = $this->report_model->getAddressidByCountryid($id);
print_r($result);
and within your model 在您的模型中
public function getAddressidByCountryid($id){
$this->db->select('c.*');
$this->db->from('Customers c');
$this->db->join('address a','c.addressID = a.addressID','left');
$this->db->where('a.countryID',$id);
$result = $this->db->get()->result_array();
return $result;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.