如何使用Codeigniter避免重复数组

时间:2018-11-10 05:12:44

标签: php html5 codeigniter

我创建了两个表,例如'iv_mail'和'iv_mail_subfeatures'。第一个表'iv_mail'包含名称,电子邮件,电话,功能名称等字段,并且'iv_mail_subfeatures'具有每个功能的子功能,我使用从两个表中获取值。实际上,我需要相应功能的子功能。如下所示,我使用了此查询, 模型

#include <stdlib.h>
#include <stdio.h>
#include <math.h>

#define _ISOC99_SOURCE

#define N 8

typedef struct _Matrix {
    double element[N][N];
} Matrix;


void PrintMatrix(Matrix a)
{
    int i;
    int j; 
    for (i=0; i<N; i++)
    {
        for (j=0; j<N; j++)
        {
            printf("%g ", a.element[i][j]);
        }//Inner for
        printf("\n");
    }//Outer For
}// printMatrix

float ComputeAverage(Matrix a)
{
    float sum;
    float average; 
    int i;
    int j; 
    for (i=0; i<N; i++)
    {
        for (j=0; j<N; j++)
        {   
            sum += a.element[i][j];
        }//inner for 
        average = sum / 64;
    }//for 
    //a.element[i][j];
    printf("Average = %.2f",average);
    printf("\n");
    // printf ("Testing Sum = %f", sum);
    //  printf("\n");
}// ComputeAverage

Matrix Q50 = {{16, 11, 10, 16, 24, 40, 51, 61,
    12, 12, 14, 19, 26, 58, 60, 55,
    14, 13, 16, 24, 40, 57, 69, 56,
    14, 17, 22, 29, 51, 87, 80, 62,
    18, 22, 37, 56, 68,109,103, 77,
    24, 35, 55, 64, 81,104,113, 92,
    49, 64, 78, 87,103,121,120,101,
    72, 92, 95, 98,112,100,103, 99}
};

int main(int argc, const char * argv[])
{
    Matrix M = {{154, 123, 123, 123, 123, 123, 123, 136,
        192, 180, 136, 154, 154, 154, 136, 110,
        254, 198, 154, 154, 180, 154, 123, 123,
        239, 180, 136, 180, 180, 166, 123, 123,
        180, 154, 136, 167, 166, 149, 136, 136,
        128, 136, 123, 136, 154, 180, 198, 154,
        123, 105, 110, 149, 136, 136, 180, 166,
        110, 136, 123, 123, 123, 136, 154, 136}};

    // need to implement PrintMatrix
    PrintMatrix(M);
    // need to implement ComputeAverage
    float ave = ComputeAverage(M);
    // need to implement round
    int dc = round(ave);
    //printf("Ave = %d\n",dc);

    return EXIT_SUCCESS;
}

控制器

 public function getmailfeatures($id)
{
$this->db->where('id',$id);
$query = $this->db->get('iv_mail'); 
$return=array();
foreach($query->result() as $getlist)
  {
 $return[$getlist->id]=$getlist;
 $subfeature_id= explode(',',$getlist->featurename);
 foreach($subfeature_id as $subfea)
    {
        $feature_id=substr($subfea,0,1);
       $return[$getlist->id]->subfeatures[]=$this->get_sub_features($id);
    }
  }
  return $return;

}
public function get_sub_features($id)
{
    $this->db->select('*');
    $this->db->where('customer_id',$id);
    $query = $this->db->get('iv_mail_subfeatures'); 
    return $query->result(); 

}

视图

 public function maildetails()
{
    $id=$this->uri->segment(3);
    $data['featuresdetails']=$this->Feature_model->getmailfeatures($id);

    $this->load->view('admin/mail/mail_details',$data);


}

它将得到两个数组,我无法打印任何人都可以帮助我的值

<p>Features</p>
                    <?php 
                    foreach($featuresdetails as $feature)
                    {
                        echo $feature->featurename  ;

                          foreach($feature->subfeatures as $sub)
                          {
                              $new_array = objectToArray($sub);
                                echo"<pre>";
                                  print_r( $new_array);
                              foreach( $new_array as $new)
                              {




                              }




                          }
                    }

                    ?>

(     [0] =>数组         (             [id] => 1             [feature_id] => 1             [customer_id] => 1             [subfeaturename] => 1_a / c         )

(
[0] => Array
    (
        [id] => 1
        [feature_id] => 1
        [customer_id] => 1
        [subfeaturename] => 1_a/c
    )

[1] => Array
    (
        [id] => 2
        [feature_id] => 1
        [customer_id] => 1
        [subfeaturename] => 1_non a/c
    )

[2] => Array
    (
        [id] => 3
        [feature_id] => 2
        [customer_id] => 1
        [subfeaturename] => 2_surya caters
    )

[3] => Array
    (
        [id] => 4
        [feature_id] => 2
        [customer_id] => 1
        [subfeaturename] => 2_test caters
    )

[4] => Array
    (
        [id] => 5
        [feature_id] => 2
        [customer_id] => 1
        [subfeaturename] => 2_dd caters
    ))
Array

0 个答案:

没有答案