我正在使用CodeIgniter和数据表。
让我们首先讨论模型。
我总共有4个访问角色,分别为1,2,3,4
,并且在代码中显示如下。
$this->session->userdata['login_session']['access_role']==4
我已经将会话设置为访问角色。因此,在模型中,我先检查访问角色,然后再处理下一个角色。
在模型中,1,2,4
访问角色没有问题。我的意思是if
条件和else
条件运行正常。
让我们讨论模型中访问角色elseif
的{{1}}条件。在这种情况下,我获得了多个记录。我的输出是
所以我在控制器中添加了多个foreach
3
所以我必须显示所有具有访问角色3的列表。
模型
foreach($order_list as $r) {
//foreach($order as $r) { }// This foreach is commented and If I remove comment then it's working but 1,2,4 not working
}
控制器
public function getCSRList($send_id){
if ($this->session->userdata['login_session']['access_role']==4) {
$this->db->select('*');
$this->db->from('tbl_customer');
$this->db->where('created_by',$send_id);
$query = $this->db->get();
$result_4 = $query->result();
return $result_4;
}
elseif ($this->session->userdata['login_session']['access_role']==3) {
$this->db->select('id');
$this->db->from('tbl_employee');
$this->db->where('team_leadername', $send_id);
$query = $this->db->get();
$result = $query->result();
if($result)
{
$result_2= array();
foreach($result as $id){
$this->db->select('*');
$this->db->from('tbl_customer');
$this->db->where('created_by',$id->id);
$query = $this->db->get();
$result_2[] = $query->result();
}
return $result_2;
}
else
{
return 0;
}
}
else{
$this->db->select('*');
$this->db->from('tbl_customer');
$query = $this->db->get();
$result = $query->result();
return $result;
}
}
答案 0 :(得分:0)
使用以下代码更新您的foreach代码
$data = array();
foreach($order_list as $order) {
if(is_array($order)){
foreach($order as $r) {
$encryption_id=base64_encode($this->encryption->encrypt($r->cust_id));
if ($r->status == -1){
$order_status='<a href="#">Action name</a>';
}elseif($r->status == 0){
$order_status='<a href="#">Action name</a>';
}elseif($r->status == 1){
$order_status='<a href="#">Action name</a>';
}else{
$order_status='<a href="#">Action name</a>';
}
if ($r->status_confirm == -1){
$order_status_confirm='<a href="#">Action name</a>';
}elseif($r->status_confirm == 3){
$order_status_confirm='<a href="#">Action name</a>';
}elseif($r->o_order_status_confirm == 1){
$order_status_confirm='<a href="#">Action name</a>';
}elseif($r->o_order_status_confirm == 2){
$order_status_confirm='<a href="#">Action name</a>';
}else{
$order_status_confirm="";
}
$action='<a href="#">Action name</a>';
if ($r->follow == 1) {
$follow='<a href="#">Action name</a>';
}else{
$follow='<a href="#">Action name</a>';
}
$data[] = array(
"Sr_No" => $n,
"cust_id" =>$encryption_id,//encrpt the id
"Name"=>$r->c_firstname."".$r->c_lastname,
"Mobile"=>$r->c_mobileno,
"orderStatus"=>"<div class='in_oneLine'>".$order_status." ".$order_status_confirm."</div>",
"action"=>"<div class='in_oneLine'>".$action." ".$follow."</div>"
);
$n++;
}
}else{
$encryption_id=base64_encode($this->encryption->encrypt($order->cust_id));
if ($order->status == -1){
$order_status='<a href="#">Action name</a>';
}elseif($order->status == 0){
$order_status='<a href="#">Action name</a>';
}elseif($order->status == 1){
$order_status='<a href="#">Action name</a>';
}else{
$order_status='<a href="#">Action name</a>';
}
if ($order->status_confirm == -1){
$order_status_confirm='<a href="#">Action name</a>';
}elseif($order->status_confirm == 3){
$order_status_confirm='<a href="#">Action name</a>';
}elseif($order->o_order_status_confirm == 1){
$order_status_confirm='<a href="#">Action name</a>';
}elseif($order->o_order_status_confirm == 2){
$order_status_confirm='<a href="#">Action name</a>';
}else{
$order_status_confirm="";
}
$action='<a href="#">Action name</a>';
if ($order->follow == 1) {
$follow='<a href="#">Action name</a>';
}else{
$follow='<a href="#">Action name</a>';
}
$data[] = array(
"Sr_No" => $n,
"cust_id" =>$encryption_id,//encrpt the id
"Name"=>$order->c_firstname."".$order->c_lastname,
"Mobile"=>$order->c_mobileno,
"orderStatus"=>"<div class='in_oneLine'>".$order_status." ".$order_status_confirm."</div>",
"action"=>"<div class='in_oneLine'>".$action." ".$follow."</div>"
);
$n++;
}
}