Skip to main content
added 29 characters in body
Source Link
Dennis
  • 281
  • 1
  • 11
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.

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;
}
$spec = new Spec();

/*
 * Load of static parameters ($q, $sg, $n) from DB omitted for clarity
 */
$s->id = 5;
$s->load();
$spec->calcPressure();
$json = json_encode($spec);

Loading

See method load in updated class.

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
 */
$spec->id = 5;
$spec->load();
$spec->calcPressure();
$json = json_encode($spec);
added 8 characters in body
Source Link
Dennis
  • 281
  • 1
  • 11
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;
}
$spec = new Spec();

/*
 * Load of static parameters ($q, $sg, $n) from DB omitted for clarity
 */
load($s->id = 5;
$s->load();
$spec->calcPressure();
$json = json_encode($spec);
/*
 * Part of Spec
 */  

function load() { $result = db_query("SELECT * from spec where id = $this->id"); $row = db_fetch_array($result); $s->n = $row['n']; $s->sg = $row['sg']; $s->q = $row['q']; }See method load in updated class.

class Spec
{

    /**
     * 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;
}
$spec = new Spec();

/*
 * Load of static parameters ($q, $sg, $n) from DB omitted for clarity
 */
load($s);
$spec->calcPressure();
$json = json_encode($spec);
/*
 * Part of Spec
 */  

function load() { $result = db_query("SELECT * from spec where id = $this->id"); $row = db_fetch_array($result); $s->n = $row['n']; $s->sg = $row['sg']; $s->q = $row['q']; }

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;
}
$spec = new Spec();

/*
 * Load of static parameters ($q, $sg, $n) from DB omitted for clarity
 */
$s->id = 5;
$s->load();
$spec->calcPressure();
$json = json_encode($spec);

See method load in updated class.

updates as requested
Source Link
Dennis
  • 281
  • 1
  • 11

Dump

function dump($sql){print "<pre>";print_r($sql);print"</pre>" . PHP_EOL;}

Loading

/*
 * Part of Spec
 */  

function load() { $result = db_query("SELECT * from spec where id = $this->id"); $row = db_fetch_array($result); $s->n = $row['n']; $s->sg = $row['sg']; $s->q = $row['q']; }

Dump

function dump($sql){print "<pre>";print_r($sql);print"</pre>" . PHP_EOL;}

Loading

/*
 * Part of Spec
 */  

function load() { $result = db_query("SELECT * from spec where id = $this->id"); $row = db_fetch_array($result); $s->n = $row['n']; $s->sg = $row['sg']; $s->q = $row['q']; }

Source Link
Dennis
  • 281
  • 1
  • 11
Loading