是否有可能返回$ var1& Codeigniter中的$ var2?

时间:2014-11-07 12:02:45

标签: php codeigniter

让我们在我的模型中说,我有一个函数查询和变量数组。我需要将变量$ m传递回我的控制器以显示在我的视图中。

模型

  for($i=1; $i<=12;)
    {
     $month=array("","01","2","3","4","5","6","7","8","9","10","11","12");
    $m = $month[$i];
    $query2=$this->db->query("
        SELECT 
          COUNT(*) AS rr 
        FROM
          trans_email 
        WHERE lup LIKE '2014-$m%' 
        ");
    $resultarray[$i]=$query2->result();
    foreach($resultarray[$i] as $row)
            {
              $data[$i] = $row;
            }
             $i++;


    }
    return $data;

控制器

$this->load->model('dash_model');
$ind = $this->dash_model->monthreport();
 $data= array();
 $data['mont'] = $ind;  
 $this->parser->parse('blank.htm', $data);

查看

{mont}
{rr}
{/mont}

输出数组$ data

 [mont] => Array
    (
        [1] => stdClass Object
            (
                [rr] => 1
            )

        [2] => stdClass Object
            (
                [rr] => 0
            )

        [3] => stdClass Object
            (
                [rr] => 0
            )

        [4] => stdClass Object
            (
                [rr] => 0
            )

        [5] => stdClass Object
            (
                [rr] => 0
            )

        [6] => stdClass Object
            (
                [rr] => 0
            )

        [7] => stdClass Object
            (
                [rr] => 0
            )

        [8] => stdClass Object
            (
                [rr] => 0
            )

        [9] => stdClass Object
            (
                [rr] => 0
            )

        [10] => stdClass Object
            (
                [rr] => 4
            )

        [11] => stdClass Object
            (
                [rr] => 9
            )

        [12] => stdClass Object
            (
                [rr] => 0
            )

我如何将var $ m返回给控制器以获得值1 - 12?

1 个答案:

答案 0 :(得分:2)

将两个变量都放入数组$my_data_array并将其返回为

for($i=1; $i<=12;)
{
   $month=array("","01","2","3","4","5","6","7","8","9","10","11","12");
   $m = $month[$i];
   $query2=$this->db->query("
    SELECT 
      COUNT(*) AS rr 
    FROM
      trans_email 
    WHERE lup LIKE '2014-$m%' 
    ");
   $resultarray[$i]=$query2->result();
   foreach($resultarray[$i] as $row)
   {
       $data[$i] = $row;
   }
   $i++;
}
$my_data_array['month'] = $m;
$my_data_array['data'] = $data;
return $my_data_array;