gpt4 book ai didi

php - 如何将多个参数传递给 codeigniter 中的函数或查询

转载 作者:行者123 更新时间:2023-11-30 22:45:58 25 4
gpt4 key购买 nike

我想要的是获取所有地址国家/地区为印度的客户的个人资料。

我有两个表customersaddress。 'customers' 表有 address_ID,在 address 表中我有 country_ID

到目前为止我试过的是这样的:

在 ajax 调用中,我得到了这个 Controller 的功能:

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();

在模型中,我根据下拉选择从 address 表中获取 country_ID,然后根据以下内容从 customers 表中获取客户的个人资料数据address_ID

型号:

    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();
}

问题是当从第二个函数 get_customer_by_addressId 获取时,我只得到最后一个 address_ID 和最后一个 customerID

我做错了什么? Controller 功能是否未传递所有 addres_ID?

表结构

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 |
+-----------+-----------+------------------+-----+

结果表

+----+-------+-----------+
| id | name | addressID |
+----+-------+-----------+
| 1 | demo | 12 |
| 2 | test | 13 |
| 3 | demo1 | 14 |
+----+-------+-----------+

现在我想要countryID为1的所有客户的数据

最佳答案

所以我正在更新您的代码,如下所示。

Controller

$result = $this->report_model->getAddressidByCountryid($id);
print_r($result);

在你的模型中

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;
}

关于php - 如何将多个参数传递给 codeigniter 中的函数或查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29604181/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com