I have a form that people fill out and a results page which displays results as follows;
I'd like to order these divs from top to bottom based on the percentage found while also retaining the colour border wanted for that category. I know some php but not entirely sure how i'd tackle this ordering, any advice would be great.
I have an idea on how to order the divs by putting the results into an array and ordering it, but i'm not sure on how id print the display with the correct border.
Below is the php I have an the display of my divs;
@php
$varA = App\Http\Controllers\ViewTeacherResults::teacherResultsInt();
$varB = App\Http\Controllers\ViewTeacherResults::teacherResultsCre();
$varC = App\Http\Controllers\ViewTeacherResults::teacherResultsSoc();
$varD = App\Http\Controllers\ViewTeacherResults::teacherResultsPer();
$varE = App\Http\Controllers\ViewTeacherResults::teacherResultsMuc();
$varF = App\Http\Controllers\ViewTeacherResults::teacherResultsMoc();
$varG = App\Http\Controllers\ViewTeacherResults::teacherResultsSp();
@endphp
<div class="table-container">
<div class="table-item intellect-border">Intellectual: {{round($varA)}}%</div>
<div class="table-item create-border">Creative: {{round($varB)}}%</div>
<div class="table-item social-border">Social: {{round($varC)}}%</div>
<div class="table-item percept-border">Perceptual: {{round($varD)}}%</div>
<div class="table-item musc-border">Muscular: {{round($varE)}}%</div>
<div class="table-item motor-border">Motor: {{round($varF)}}%</div>
<div class="table-item spir-border">Spiritual: {{round($varG)}}%</div>
</div>
CodePudding user response:
You can store it as an array like this
$array = [
[
'name' => 'Intellectual',
'border' => 'intellect-border',
'val' => $varA,
],
[
'name' => 'Creative',
'border' => 'create-border',
'val' => $varB,
],
[
'name' => 'Social',
'border' => 'social-border',
'val' => $varC,
]
];
Because your question is relevant, then you can use usort for sorting, check here
Note : check this line for ascending sort
$item1['val'] <=> $item2['val'];
and you can swap to this if you want descending sort
$item2['val'] <=> $item1['val'];