繁体   English   中英

在PHP中将函数传递给html

[英]Passing function to html in php

我正在尝试复制一个函数并将其传递给网站的主体,但是由于某种原因它甚至没有加载标头,我认为这是因为未正确传递某些东西。

这与几乎完全相同格式的同一文件中的另一个功能一起使用。 唯一的区别是工作函数使用$_SESSION[dealernum] ,而我尝试获取的函数没有会话变量,而是使用下拉菜单$swrapper->getRepNum() select选项。

这是我要加载的功能:

private function loadPlacement($custno){
    $custno += 0;
    $this->mysqlConnect();

    $sql1 = " SELECT count(dealer_id), start_date as period, sum(placements), sum(pieces)
            FROM placements p
            inner join dealers d
            on p.dealer_id = d.dealer_num
             WHERE d.sales_rep = {$custno}
             and p.start_date between '{$this->py_from}' and '{$this->py_thru}'
           ";

        $result1 = mysql_connect($this->mysqli, $sql1);

        $this->placeSnap = array();

        while ($row1 = mysqli_fetch_assoc($result1)) {
            $this->placeSnap[$row1['PERIOD']] = round($row1['placements'],0);
            $this->isloaded = true;
        }

        if ($this->placeSnap['PY_YTD'] == 0) {
            $this->placeSnap['PCT'] = 0;
        } else {
            $this->placeSnap['PCT'] = ($this->placeSnap['CY_YTD']-$this->placeSnap['PY_YTD']) / $this->placeSnap['PY_YTD'];
            $this->placeSnap['PCT'] = round( $this->placeSnap['PCT'] * 100, 0);
            $this->placeSnap['PCT'] = min(array($this->placeSnap['PCT'], 999));
        }
    }


/**
 * HTML for placement snapshot table
 * 
 * @param int $custno
 * @param string $header
 * @return string
 */
function getPlacementSnapshotHTML($custno, $header='Placement Snapshot') {

    $this->loadPlaceSnap($custno);

    $h1 = "<table class='customer-volume-snapshot-table'>";
    $h1 .= "<thead><tr><th colspan='2'>" . htmlspecialchars($header) . "</th></tr></thead>";
    $h1 .= "<tbody>";
    $h1 .= "<tr><td>{$this->pyyy} YTD</td><td style='text-align: right;'>$" . number_format($this->placeSnap['PY_YTD']) . "</td></tr>";
    $h1 .= "<tr><td>{$this->yyyy} YTD</td><td style='text-align: right;'>$" . number_format($this->placeSnap['CY_YTD']) . "</td></tr>";
    $h1 .= "<tr><td>Percent Change</td><td style='text-align: right;'>{$this->salessum['PCT']}%</td></tr>";
    $h1 .= "<tr><td>{$this->pyyy} Full Year</td><td style='text-align: right;'>$" . number_format($this->placeSnap['PY_FULL']) . "</td></tr>";
    $h1 .= "</tbody></table>";

    return $h1;
}

这是我要加载的HTML:

if(!empty($swrapper->getRepNum())){
    echo "<table><td>";
    echo "Rep Number {$swrapper->getRepNum()}"; //This is loading the rep number correctly
    $h1 = $custdash->getPlacementSnapshotHTML($swrapper->getRepNum(), "Placement Snapshot For Rep {$swrapper->getRepNum()}"); //This is not loading at all
    echo "<div style='border: 1px solid black; margin: 3px; padding: 3px;'>";
    echo "</table></td>";

}

代表编号的回显显示出来,但该功能什么也没有显示。 也许我忽略了一些东西。

应该是这样

echo "Rep Number ".$swrapper->getRepNum();
$h1 = $custdash->getPlacementSnapshotHTML($swrapper->getRepNum()."Placement Snapshot For Rep ".$swrapper->getRepNum()); //This is not loading at all
            echo "<div style='border: 1px solid black; margin: 3px; padding: 3px;'>";

它将打印返回值

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM