我遇到了一个小问题,我似乎无法弄清楚。我有一个计算类,可以根据各种值计算 som 数量,并且我需要将这些计算值放在另一个函数中,该函数将输出包含数量、价格等的列表。
但我无法获得价值。我只是得到:
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;
}
}