Very new to PHP and JSON, I'm using the following to display a list of rows:
$db = new PDO('mysql:host=localhost;dbname=rugbysuperleague','xxx','xxx');
$stmt = $db->query("SELECT * FROM `table`");
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt->execute();
echo json_encode($data);
It returns all the rows in the table OK, But how do I return the rows sorted based on aAscending values of a specific column, if tie, sort by next column. etc.
I'm trying to list in correct order a Sports Team Standings table. So that the team with most points is in 1st position, if there is a tie, sort by point difference etc.
order byin your sql query? json is just a string. it has no "order". you'd have to build your JS data structure in whatever order you want if you want the json to be ordered, and there's no guarantee that what you stuff into a JSON string will be in the same order it was in the original JS structure.