mysql - how to read/decipher a user defined mathematical formula and perform requested operation in php -


i have user defined formula stored in mysql table avg({arrival_date}-{departure_date}) managed items arrival_date , departure_date select rows separate table.

how can replace {arrival_date} , {departure_date} avg({arrival_date}-{departure_date}) actual data selected database table?

hi suggestion. solved above using https://github.com/jlawrence11/eos. there no need of trying decipher formula long follows bodmas rule.

you read formula defined, pass values(numbers or floats) formula , call eos computation.

example:

  <?php        $formula_as_defined = avg({arrival_date}-{departure_date})  ; //get formula database        $str= str_ireplace('{','',$formula_as_defined);       $mod_str= str_ireplace('}','',$str);       $mod_str;       //  foreach($sql_select_resultset $array) //this array of values selected db table #1 => arrival_date #2 =>departure_date               {                   foreach($array $key => $value)                   {                       $col_mod[]= $key;                        $val_mod[]= strtotime($value);                       //                   }                     $char_mod = str_ireplace($col_mod,$val_mod,$mod_str);                     unset($col_mod);                     unset($val_mod);                     //                   //   $equation = "(".strtotime('13-07-2015')."-".strtotime('20-07-2015').")";                      $equation = $char_mod  ;                      $eq = new eqeos();                      $result = $eq->solveif($equation); //pass formula solveif , done.                      //                      $myresults = $this->groupdata($myresults,$array,$x_axis_column,$results_type_time);                      array_push($myresults[date('m',strtotime($array[$x_axis_column]))],$result);                }      ?> 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

jquery - javascript onscroll fade same class but with different div -