mardi 27 novembre 2018

php if statement argument in laravel

I have a calculation to make which the variable $totalPercent might be a 0 so I added some if statements to the script to only run since the initial returned with an error on division by zero on some occasion.

This was the newly revised calculation, which now works when $totalPercent is a 0, but when it has a value and the supposed script is called, it returned me an error of Undefined variable: designPercent

Here is the new script with the added if statement that was meant to do calculation only if $totalPercent is more than 0.

@if ($totalnumerical > '0')
    $totalPercent= '100' / $totalnumerical;
    $stylePercent= ($styletempt *  $totalPercent).'%';
    $designPercent= ($designtempt * $totalPercent).'%';
    $managePercent= ($managetempt * $totalPercent).'%';
    <div class="graphSection">
        <div class="skillGraph">
            <span style="width:" class="bar-1"></span>
            <span style="width:" class="bar-2"></span>
            <span style="width:" class="bar-3"></span>
        </div><br>
        <div class="skillGraph graph_text">
            @if(($designtempt * $totalPercent) > 15)
                <span style="width:" >Design</span>
            @else
                <span class="hovertext" style="width:; margin-top:-57px" >Design</span>
                <span style="width:" ></span>
            @endif
            @if(($styletempt * $totalPercent) > 15)
                <span style="width:" >Interior Styling</span>
            @else
                <span class="hovertext" style="width:; margin-top:-67px;" >Interior Styling</span>
                <span style="width:" ></span>
            @endif
            <span style="width:" >Project Management</span>
        </div>
    </div>

@endif

Aucun commentaire:

Enregistrer un commentaire