如何从Query中获取值

时间:2016-03-30 10:00:15

标签: php sql-server-2008 codeigniter-2

请先检查我的脚本。

    $arealeader = $this->db->query("select OutletCode from arealeader where NipLeader = '$Nip'")->result();
            $Mp=array();
            foreach($arealeader as $row)
            {
                $Mp[] = $this->db->query("select Nip from Employee where OutletCode = '".$row->OutletCode."'")->result();
                $MpCount[] =  $this->db->query("select Nip from Employee where OutletCode = '".$row->OutletCode."'")->num_rows();

            }   

           echo array_sum($MpCount) // Result 18 
            foreach($Mp as $row)
            {
                echo $row->Nip."<br>";
            }

我的脚本如何工作:在$Arealeader中,我从条件中选择每个OutletCode。在我拥有OutletCode之后,我想从Nip来自OutletCode的员工中选择echo $row->Nip."<br>";作为条件。

问题: var_dump($row);` i get this `array(1) { [0]=> object(stdClass)#52 (1) { ["Nip"]=> string(9) "201603172" } } 时。我只得到白屏。

DATA in_data ; 
   INPUT Category $ Month $ var_0 - var_9 ; 
   DATALINES; 
Categ_1 Month_1 15 15 15 14 14 13 13 13 13 13
Categ_1 Month_2 8 8 8 7 6 5 5 5 5 5
Categ_1 Month_3 15 15 14 14 14 12 11 11 11 10
Categ_1 Month_4 17 17 17 15 14 14 13 12 11 11
Categ_1 Month_5 25 25 25 23 21 19 18 16 16 16
Categ_1 Month_6 21 21 18 17 14 13 12 11 11 8
Categ_1 Month_7 29 28 25 23 20 18 15 14 13 13
Categ_1 Month_8 32 31 30 28 25 23 21 20 18 17
Categ_1 Month_9 38 37 35 32 27 24 23 20 17 16
Categ_1 Month_10 30 30 28 27 24 21 20 18 17 17

; 

data out_data;
do until (last.Category);
    set in_data;
    format out_0 - out_9 percent.;
    array in  [*] var_0 - var_9;
    array out [*] out_0 - out_9;
    by Category;
    if first.Category then count = 0;
    count + 1;
    do i = 1 to dim(in) + 1 - count;
        out[i] = sum(out[i],in[i]);
        if dim(in) + 1 - i = count then out[i] = out[i] /out[1];
    end; 
end;
    drop var_: month i count;
run;

1 个答案:

答案 0 :(得分:0)

ivar : You should join those queries so it is only 1 query. That can save you a lot of performance

我更改了上面的脚本并更改为此内容。

$data['master'] = $this->db->query("select a.*,b.fullname from SaldoCuti a 
                  left join employee b on a.Nip = b.Nip
                  left join outlet c on b.OutletCode = c.OutletCode
                  left join arealeader d on c.OutletCode = d.OutletCode     
                  where NipLeader = '$Nip'")->result();

我发现现在它对我来说很好。如果你们有更好的方法,请告诉我。