Access role with multiple foreach not working





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-1















I am using CodeIgniter and data tables.



Let's talk about Model first.



I have total 4 access role which are 1,2,3,4 and I am displaying like this in the code.



$this->session->userdata['login_session']['access_role']==4


I already set the session for access role. So in the model, I am checking the access role first and then it will process for the next.



In the Model, There is no issue with 1,2,4 access role. I mean if condition and else condition is working perfectly.



Let's talk about elseif condition for access role 3 in model. I am getting more than one record in this condition. and my output is
enter image description here



So I added more than one foreach in the controller



 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
}


So I have to display all the list which are in the access role 3.



Model



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

}


Controller



    public function order_listdetails(){
$send_id =$this->session->userdata['login_session']['id'];
$order_list=$this->Customer_model->getCSRList($send_id);//getting from model

// Datatables Variables
$draw = intval($this->input->get("draw"));
$start = intval($this->input->get("start"));
$length = intval($this->input->get("length"));

$data['draw'] = 1;
$recordsTotal = count($order_list);
$recordsFiltered = count($order_list);

$data = array();
$n=1;
if(is_array($order_list)){
foreach($order_list as $r) {
//foreach($order as $r) {// remove comment then working for 3 but not working for 1,2,4
$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++;
}
}
//}
$output = array(
"draw" => $draw,
"recordsTotal" => $recordsTotal,
"recordsFiltered" =>$recordsFiltered,
"data" => $data
);
echo json_encode($output);
exit();
}









share|improve this question

























  • from where you got $order data

    – Sachin
    Nov 16 '18 at 12:43













  • @Sachin, I tried foreach($order_list as $order) { foreach($order as $r) { }} and it's working..but not working for 1,2,4

    – user9437856
    Nov 16 '18 at 12:55













  • so you want retrive above printed array right?

    – Sachin
    Nov 16 '18 at 12:57











  • Yes, that's right. even I am getting from model but not able to display in controller

    – user9437856
    Nov 16 '18 at 13:01













  • can you share your printed array in text instead of the image so i can provide you correct solution

    – Sachin
    Nov 16 '18 at 13:02


















-1















I am using CodeIgniter and data tables.



Let's talk about Model first.



I have total 4 access role which are 1,2,3,4 and I am displaying like this in the code.



$this->session->userdata['login_session']['access_role']==4


I already set the session for access role. So in the model, I am checking the access role first and then it will process for the next.



In the Model, There is no issue with 1,2,4 access role. I mean if condition and else condition is working perfectly.



Let's talk about elseif condition for access role 3 in model. I am getting more than one record in this condition. and my output is
enter image description here



So I added more than one foreach in the controller



 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
}


So I have to display all the list which are in the access role 3.



Model



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

}


Controller



    public function order_listdetails(){
$send_id =$this->session->userdata['login_session']['id'];
$order_list=$this->Customer_model->getCSRList($send_id);//getting from model

// Datatables Variables
$draw = intval($this->input->get("draw"));
$start = intval($this->input->get("start"));
$length = intval($this->input->get("length"));

$data['draw'] = 1;
$recordsTotal = count($order_list);
$recordsFiltered = count($order_list);

$data = array();
$n=1;
if(is_array($order_list)){
foreach($order_list as $r) {
//foreach($order as $r) {// remove comment then working for 3 but not working for 1,2,4
$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++;
}
}
//}
$output = array(
"draw" => $draw,
"recordsTotal" => $recordsTotal,
"recordsFiltered" =>$recordsFiltered,
"data" => $data
);
echo json_encode($output);
exit();
}









share|improve this question

























  • from where you got $order data

    – Sachin
    Nov 16 '18 at 12:43













  • @Sachin, I tried foreach($order_list as $order) { foreach($order as $r) { }} and it's working..but not working for 1,2,4

    – user9437856
    Nov 16 '18 at 12:55













  • so you want retrive above printed array right?

    – Sachin
    Nov 16 '18 at 12:57











  • Yes, that's right. even I am getting from model but not able to display in controller

    – user9437856
    Nov 16 '18 at 13:01













  • can you share your printed array in text instead of the image so i can provide you correct solution

    – Sachin
    Nov 16 '18 at 13:02














-1












-1








-1








I am using CodeIgniter and data tables.



Let's talk about Model first.



I have total 4 access role which are 1,2,3,4 and I am displaying like this in the code.



$this->session->userdata['login_session']['access_role']==4


I already set the session for access role. So in the model, I am checking the access role first and then it will process for the next.



In the Model, There is no issue with 1,2,4 access role. I mean if condition and else condition is working perfectly.



Let's talk about elseif condition for access role 3 in model. I am getting more than one record in this condition. and my output is
enter image description here



So I added more than one foreach in the controller



 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
}


So I have to display all the list which are in the access role 3.



Model



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

}


Controller



    public function order_listdetails(){
$send_id =$this->session->userdata['login_session']['id'];
$order_list=$this->Customer_model->getCSRList($send_id);//getting from model

// Datatables Variables
$draw = intval($this->input->get("draw"));
$start = intval($this->input->get("start"));
$length = intval($this->input->get("length"));

$data['draw'] = 1;
$recordsTotal = count($order_list);
$recordsFiltered = count($order_list);

$data = array();
$n=1;
if(is_array($order_list)){
foreach($order_list as $r) {
//foreach($order as $r) {// remove comment then working for 3 but not working for 1,2,4
$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++;
}
}
//}
$output = array(
"draw" => $draw,
"recordsTotal" => $recordsTotal,
"recordsFiltered" =>$recordsFiltered,
"data" => $data
);
echo json_encode($output);
exit();
}









share|improve this question
















I am using CodeIgniter and data tables.



Let's talk about Model first.



I have total 4 access role which are 1,2,3,4 and I am displaying like this in the code.



$this->session->userdata['login_session']['access_role']==4


I already set the session for access role. So in the model, I am checking the access role first and then it will process for the next.



In the Model, There is no issue with 1,2,4 access role. I mean if condition and else condition is working perfectly.



Let's talk about elseif condition for access role 3 in model. I am getting more than one record in this condition. and my output is
enter image description here



So I added more than one foreach in the controller



 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
}


So I have to display all the list which are in the access role 3.



Model



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

}


Controller



    public function order_listdetails(){
$send_id =$this->session->userdata['login_session']['id'];
$order_list=$this->Customer_model->getCSRList($send_id);//getting from model

// Datatables Variables
$draw = intval($this->input->get("draw"));
$start = intval($this->input->get("start"));
$length = intval($this->input->get("length"));

$data['draw'] = 1;
$recordsTotal = count($order_list);
$recordsFiltered = count($order_list);

$data = array();
$n=1;
if(is_array($order_list)){
foreach($order_list as $r) {
//foreach($order as $r) {// remove comment then working for 3 but not working for 1,2,4
$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++;
}
}
//}
$output = array(
"draw" => $draw,
"recordsTotal" => $recordsTotal,
"recordsFiltered" =>$recordsFiltered,
"data" => $data
);
echo json_encode($output);
exit();
}






php codeigniter-3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 17 '18 at 5:12







user9437856

















asked Nov 16 '18 at 12:30









user9437856user9437856

481314




481314













  • from where you got $order data

    – Sachin
    Nov 16 '18 at 12:43













  • @Sachin, I tried foreach($order_list as $order) { foreach($order as $r) { }} and it's working..but not working for 1,2,4

    – user9437856
    Nov 16 '18 at 12:55













  • so you want retrive above printed array right?

    – Sachin
    Nov 16 '18 at 12:57











  • Yes, that's right. even I am getting from model but not able to display in controller

    – user9437856
    Nov 16 '18 at 13:01













  • can you share your printed array in text instead of the image so i can provide you correct solution

    – Sachin
    Nov 16 '18 at 13:02



















  • from where you got $order data

    – Sachin
    Nov 16 '18 at 12:43













  • @Sachin, I tried foreach($order_list as $order) { foreach($order as $r) { }} and it's working..but not working for 1,2,4

    – user9437856
    Nov 16 '18 at 12:55













  • so you want retrive above printed array right?

    – Sachin
    Nov 16 '18 at 12:57











  • Yes, that's right. even I am getting from model but not able to display in controller

    – user9437856
    Nov 16 '18 at 13:01













  • can you share your printed array in text instead of the image so i can provide you correct solution

    – Sachin
    Nov 16 '18 at 13:02

















from where you got $order data

– Sachin
Nov 16 '18 at 12:43







from where you got $order data

– Sachin
Nov 16 '18 at 12:43















@Sachin, I tried foreach($order_list as $order) { foreach($order as $r) { }} and it's working..but not working for 1,2,4

– user9437856
Nov 16 '18 at 12:55







@Sachin, I tried foreach($order_list as $order) { foreach($order as $r) { }} and it's working..but not working for 1,2,4

– user9437856
Nov 16 '18 at 12:55















so you want retrive above printed array right?

– Sachin
Nov 16 '18 at 12:57





so you want retrive above printed array right?

– Sachin
Nov 16 '18 at 12:57













Yes, that's right. even I am getting from model but not able to display in controller

– user9437856
Nov 16 '18 at 13:01







Yes, that's right. even I am getting from model but not able to display in controller

– user9437856
Nov 16 '18 at 13:01















can you share your printed array in text instead of the image so i can provide you correct solution

– Sachin
Nov 16 '18 at 13:02





can you share your printed array in text instead of the image so i can provide you correct solution

– Sachin
Nov 16 '18 at 13:02












1 Answer
1






active

oldest

votes


















0














Update your foreach code with below code



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





share|improve this answer


























  • Give me some time to understand your answer

    – user9437856
    Nov 16 '18 at 13:13











  • Sure take your own time.

    – Sachin
    Nov 16 '18 at 13:18











  • Yes, I am getting the output correct but now I am not able to get the out of 1,2,4

    – user9437856
    Nov 16 '18 at 13:24











  • not getting what you sey can you please explain more clear?

    – Sachin
    Nov 16 '18 at 13:27











  • you mean in role 1,2,4 there is no inside array right?

    – Sachin
    Nov 16 '18 at 13:29












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337964%2faccess-role-with-multiple-foreach-not-working%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Update your foreach code with below code



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





share|improve this answer


























  • Give me some time to understand your answer

    – user9437856
    Nov 16 '18 at 13:13











  • Sure take your own time.

    – Sachin
    Nov 16 '18 at 13:18











  • Yes, I am getting the output correct but now I am not able to get the out of 1,2,4

    – user9437856
    Nov 16 '18 at 13:24











  • not getting what you sey can you please explain more clear?

    – Sachin
    Nov 16 '18 at 13:27











  • you mean in role 1,2,4 there is no inside array right?

    – Sachin
    Nov 16 '18 at 13:29
















0














Update your foreach code with below code



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





share|improve this answer


























  • Give me some time to understand your answer

    – user9437856
    Nov 16 '18 at 13:13











  • Sure take your own time.

    – Sachin
    Nov 16 '18 at 13:18











  • Yes, I am getting the output correct but now I am not able to get the out of 1,2,4

    – user9437856
    Nov 16 '18 at 13:24











  • not getting what you sey can you please explain more clear?

    – Sachin
    Nov 16 '18 at 13:27











  • you mean in role 1,2,4 there is no inside array right?

    – Sachin
    Nov 16 '18 at 13:29














0












0








0







Update your foreach code with below code



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





share|improve this answer















Update your foreach code with below code



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






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 17 '18 at 5:53

























answered Nov 16 '18 at 13:09









SachinSachin

610412




610412













  • Give me some time to understand your answer

    – user9437856
    Nov 16 '18 at 13:13











  • Sure take your own time.

    – Sachin
    Nov 16 '18 at 13:18











  • Yes, I am getting the output correct but now I am not able to get the out of 1,2,4

    – user9437856
    Nov 16 '18 at 13:24











  • not getting what you sey can you please explain more clear?

    – Sachin
    Nov 16 '18 at 13:27











  • you mean in role 1,2,4 there is no inside array right?

    – Sachin
    Nov 16 '18 at 13:29



















  • Give me some time to understand your answer

    – user9437856
    Nov 16 '18 at 13:13











  • Sure take your own time.

    – Sachin
    Nov 16 '18 at 13:18











  • Yes, I am getting the output correct but now I am not able to get the out of 1,2,4

    – user9437856
    Nov 16 '18 at 13:24











  • not getting what you sey can you please explain more clear?

    – Sachin
    Nov 16 '18 at 13:27











  • you mean in role 1,2,4 there is no inside array right?

    – Sachin
    Nov 16 '18 at 13:29

















Give me some time to understand your answer

– user9437856
Nov 16 '18 at 13:13





Give me some time to understand your answer

– user9437856
Nov 16 '18 at 13:13













Sure take your own time.

– Sachin
Nov 16 '18 at 13:18





Sure take your own time.

– Sachin
Nov 16 '18 at 13:18













Yes, I am getting the output correct but now I am not able to get the out of 1,2,4

– user9437856
Nov 16 '18 at 13:24





Yes, I am getting the output correct but now I am not able to get the out of 1,2,4

– user9437856
Nov 16 '18 at 13:24













not getting what you sey can you please explain more clear?

– Sachin
Nov 16 '18 at 13:27





not getting what you sey can you please explain more clear?

– Sachin
Nov 16 '18 at 13:27













you mean in role 1,2,4 there is no inside array right?

– Sachin
Nov 16 '18 at 13:29





you mean in role 1,2,4 there is no inside array right?

– Sachin
Nov 16 '18 at 13:29




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53337964%2faccess-role-with-multiple-foreach-not-working%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Xamarin.iOS Cant Deploy on Iphone

Glorious Revolution

Dulmage-Mendelsohn matrix decomposition in Python