我遇到了一个我似乎无法弄清楚的问题。 我有一个计算类,从各种值计算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-&gt; roofTiles和$ this-&gt; roofBinders给出了上面提到的致命错误。
$ this-&gt; roofTiles在Calculation类的函数中计算,如下所示:
$this->Rooftiles = ceil((($areal_tagflade*$forbrug-$antaldblvinge*$daekbredde_dv_venstre_2-$antal_topsten-2))*$perc / 2) * 2;
但是在PrintList函数中我无法获得该值。
$ matliste-&gt; 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;
}
}