I'm trying to replicate a function and pass it to the body of my site but it's not even loading the header for some reason and I think it's because something isn't being passed correctly.
This works with another function from the same file in almost the exact same format. The only difference is the working function uses $_SESSION[dealernum] and the function I'm trying to get doesn't have a session variable and it's using select option from a drop down $swrapper->getRepNum().
Here's the function I'm trying to get to load:
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;
}
And here's the HTML where I'm trying to load it:
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>";
}
The echo of the rep number shows up but nothing for the function. Maybe I'm overlooking something.
getPlacementSnapshotHTML!$h1 = $custdash->...withecho $custdash->...$this->loadPlaceSnap($custno);call does, because in your code you shown us a function calledloadPlacement($custno);(And you never call that function in your example) so I wonder if you're calling the correct function in the class. Please explain what your code supposed to doplacementsbut in your query you don't select that column - You selectsum(placements). You need to name that columnsum(placements) as placements_sum(for example), and then instead of$row1['placements']you change it to$row1['placements_sum']. The same goes for$row1['PERIOD'], not sure it indexes are case sensitive so use$row1['period']instead