I have done research but cannot find an exact working method of doing this. I tried jquery plugins and of course following stack overflow solutions sort rows of HTML table that are called from MySQL I also tried asking stackoverflow…but you can imagine how that went.
-
I query the two tables in the same database using inner join
$sql = “SELECT users.empid, users.empfirst, users.emplast,
prodata.monval, prodata.montar,
prodata.tueval, prodata.tuetar,
prodata.wedval, prodata.wedtar,
prodata.thuval, prodata.thutar,
prodata.frival, prodata.fritar
FROM users INNER JOIN prodata ON
users.empid = prodata.empid WHERE users.level = 2” ;
$result = mysqli_query($db, $sql);
// Set total variables to 0 for later use
$totalscore = 0;
$totaltarget = 0; -
then I echo these values out into a basic table within a while loop and sum values for $totalscore & $totaltarget
while($res = mysqli_fetch_array($result))
{
//Add all
echo “”;
echo “”.$res[‘empid’].“”;
echo “”.$res[‘empfirst’].“”;
echo “”.$res[‘emplast’].“”;
$totalscore = $res[‘monval’] + $res[‘tueval’] + $res[‘wedval’] + $res[‘thuval’] + $res[‘frival’];
$totaltarget = $res[‘montar’] + $res[‘tuetar’] + $res[‘wedtar’] + $res[‘thutar’] + $res[‘fritar’];
echo “”.$totalscore.“”; //Score total
echo “”.$totaltarget.“”; //Target total
}
How can I order the table contents to show in descending order, $totalscore (numeric). Is it better to do this through PHP or through the query?