Exemple #1
0
 function set_vars_from_query($q, $vn1 = null, $vn2 = null, $g = null, $g1 = null, $g2 = null)
 {
     // get independent data from query
     // $vn1 is the name of the variable to test
     // $vn2 is a placeholder
     // $g is the name of the grouping variable
     // $g1 and $g2 are the names of the first and second groups
     $query = new myQuery($q, true);
     $data = $query->get_array();
     if (count($data) == 0) {
         return false;
     }
     // check that named vars do exists,
     // if not, use first and second columns
     $var = array_key_exists($vn1, $data[0]) ? $vn1 : 0;
     $group = array_key_exists($g, $data[0]) ? $g : 1;
     // delete existing vars and add new data
     $this->var1 = array();
     $this->var2 = array();
     foreach ($data as $d) {
         if ($d[$g] == $g1 && !is_null($d[$vn1])) {
             $this->var1[] = $d[$vn1];
         } else {
             if ($d[$g] == $g2 && !is_null($d[$vn1])) {
                 $this->var2[] = $d[$vn1];
             }
         }
     }
     $this->calculate();
 }