class Spec
{
function load()
{
$result = db_query("SELECT * from spec where id = {$this->id}");
$row = db_fetch_array($result);
$this->n = $row['n'];
$this->sg = $row['sg'];
$this->q = $row['q'];
}
/**
* Computes and returns Pressure
* Outputs debug info
* Assigns internal parameter
*
* @return number
*/
function calcPressure()
{
$res = abs($this->n * sqrt($this->q) / 15164.93 * $this->sg);
dump(" *** <u>Pressure</u> = $res");
$this->pressure = $res;
return $res;
}
public $pressure;
public $sg;
public $q;
public $n;
public $id;
}
$spec = new Spec();
/*
* Load of static parameters ($q, $sg, $n) from DB omitted for clarity
*/
$s$spec->id = 5;
$s$spec->load();
$spec->calcPressure();
$json = json_encode($spec);
Loading
See method load in updated class.