I'm trying to set up a table with scores from the MODX database, this data has been entered in via tv.variables in the MODX admin panel.
My SQL code retrieves my desired data with:
SELECT sc.pagetitle, cv.value, t.name
FROM pphc_site_tmplvar_contentvalues cv, pphc_site_content sc, pphc_site_tmplvars t
WHERE sc.id = cv.contentid
AND cv.tmplvarid = t.id
ORDER BY cv.value * 1 DESC
My SQL retrieves the team name, range of team scores (plays, wins, losses, draws, total points) and if they won/lost/drew.
Below is a screenshot of what I'm after (with the SQL I can get at the moment)
My code at the moment for dealing with the SQL/loop is:
//$output = $x; //get draws, losses, played, points and wins
$id = $x; //id of current page
function sort_by_value($a, $b) {
return $b["value"] - $a["value"];
}
$sql = "SELECT sc.pagetitle, cv.value, t.name
FROM pphc_site_tmplvar_contentvalues cv, pphc_site_content sc, pphc_site_tmplvars t
WHERE sc.id = cv.contentid
AND cv.tmplvarid = t.id
AND sc.id = $id
ORDER BY cv.value * 1 DESC";
$result = $modx->query($sql)->fetchAll();
usort($result, "sort_by_value");
//print_r($result);die();
$html = '';
foreach ($result as $row) {
$html .= ''. $row['value'] .'<br>';
}
return $html;
At the moment all this code does is retrieve the results of each team - Great!
I can't seem to figure out how to lay out the data in table form AND include the team names