I'm doing this now:
$.ajax({
url: 'full_db.php',
type: 'GET',
dataType: 'JSON',
data: {col_name: firstSel},
success: function(data) {
var full_options = [];
$.each(data, function (i, data) {
full_options.push(data.age);
full_options.sort(function(a, b){
return a.age - b.age;
});
$('#second_select').append("<option>" + data.age + "</option>");
});
}
});
This appends all of the distinct ages to my select (second_select) and if I console log full_options
I get this:
["55", "98", "34", "30", "45", "29", "26", "22", "37", "42", "32", "33", "36", "35", "56", "46", "25", "54", "86"]
I'm looking to get this in ascending order (e.g.: 22, 25, 26, 29,...).
What am I doing wrong here that I'm getting an unordered array?
SELECT statement.ORDER BY column_name DESCdescendingorder. Please correct thiswhat am i doing wrong.. your sort function assumes an array of objects with propertyagebut when you pushdata.ageinto array you are only pushing in a primitive value not an object