0

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.

7
  • you never echo the return of that function getPlacementSnapshotHTML! Commented Feb 16, 2018 at 15:57
  • maybe this is what you want: replace $h1 = $custdash->... with echo $custdash->... Commented Feb 16, 2018 at 15:58
  • Not sure what $this->loadPlaceSnap($custno); call does, because in your code you shown us a function called loadPlacement($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 do Commented Feb 16, 2018 at 16:02
  • I believe that's right, I just corrected that but still no loading. Basically, the loadplacement function is using that query to acquire the data I need for sales reps and then the second function just structures the HTML for it based on the rep number Commented Feb 16, 2018 at 16:06
  • @TomN. You're also trying to fetch a column named placements but in your query you don't select that column - You select sum(placements). You need to name that column sum(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 Commented Feb 16, 2018 at 16:15

1 Answer 1

1

it should be like this

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;'>";

it will print the return values

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.