私は理解できないように見える小さな問題に直面しました。さまざまな値からいくつかの数量を計算する計算クラスがあり、数量、価格などのリストを出力する別の関数内で計算された値が必要です。
しかし、私は値を取得できません。私はただ得る:
Fatal error: Using $this when not in object context in
リストを出力する関数は、Matliste というクラス内にあります。
function PrintList($rid, $fields_to_select = array()) {
$matliste = new Matliste;
$matliste->GetCalculation($_GET["house"]);
$types = join(",", $fields_to_select);
$sql = "SELECT * FROM nt_stentyper INNER JOIN nt_tunliste ON nt_stentyper.varenr_tilb = nt_tunliste.varenummer INNER JOIN nt_priser ON nt_stentyper.varenr_tilb = nt_priser.varenummer WHERE nt_stentyper.tagsten = $rid AND nt_stentyper.prod_type IN ($types) ORDER BY nt_stentyper.prod_type ASC";
$result = mysql_query($sql);
$markers = array();
$markers["###TABLEROWS###"] = "";
$prodTypes = array("1" => $this->roofTiles, "2" => $this->roofBinders);
while($row = mysql_fetch_array($result)) {
$markers["###TABLEROWS###"] .= '<tr>';
$markers["###TABLEROWS###"] .= "<td>". $row["varenummer"] ."</td>";
$markers["###TABLEROWS###"] .= "<td>". $row["tunnummer"] ."</td>";
$markers["###TABLEROWS###"] .= "<td>". $row["beskrivelse"] ."</td>";
$markers["###TABLEROWS###"] .= "<td>". $prodTypes[$row["prod_type"]] ."</td>";
$markers["###TABLEROWS###"] .= "<td>stk</td>";
$markers["###TABLEROWS###"] .= "<td>". str_replace(".", ",", $row["pris_dk"]) ." kr.</td>";
}
$finalPrice = mysql_fetch_array(mysql_query("SELECT *, SUM(pris_dk) AS pris FROM nt_stentyper INNER JOIN nt_tunliste ON nt_stentyper.varenr_tilb = nt_tunliste.varenummer INNER JOIN nt_priser ON nt_stentyper.varenr_tilb = nt_priser.varenummer WHERE nt_stentyper.tagsten = $rid AND nt_stentyper.prod_type IN ($types)"));
$markers["###FINALPRICE###"] = str_replace(".", ",", $finalPrice["pris"]);
$markers["###LIST_FOR###"] = ($finalPrice["prod_type"] == 1) ? $finalPrice["beskrivelse"] : "";
$markers["###PERCENTAGE###"] = $_GET["spild"];
Main::GetMarkers($markers);
}
$this->roofTiles と $this->roofBinders を使用すると、上記の致命的なエラーが発生します。
$this->roofTiles は、Calculation クラスの関数で計算され、次のようになります。
$this->Rooftiles = ceil((($areal_tagflade*$forbrug-$antaldblvinge*$daekbredde_dv_venstre_2-$antal_topsten-2))*$perc / 2) * 2;
しかし、PrintList 関数ではその値を取得できません。
$matliste->GetCalculation は次のとおりです。
function GetCalculation($house) {
$calculations = new HouseCalculations;
switch($house) {
case 1:
$calculations->calc_normal($_GET["rid"], $_GET["rooftiletype"], $_GET["afslutning_sten"], (isset($_GET["wa"])) ? $_GET["wa"] : 0, (isset($_GET["kviste_1"])), (isset($_GET["kviste_2"])));
break;
}
}