My page has two columns. Column1 for player1, column2 for player2. For each column I have a dropdown to choose one of the players.
With some ajax en php codes I return the folowing info of each player. For example:
Col1: Tom, Football: 8 points Basketball: 5 points
Col2: Jonathan, Football: 4 points Basketball: 9 points
Now I want to let the users sort the results: So I add another dropdown in each column:
PHP
echo "<select id='filter_class' name=\"filter\"
data-userid=\"".$user_id."\" onchange=\"getFilter(this.value)\">
<option value=\"all\">All</option>
<option value=\"asc\">Asc</option>
<option value=\"desc\">Desc</option>
</select>";
AJAX
function getFilter(filter)
{
var user_id = document.getElementById('filter_class').getAttribute('data-userid');
console.log(user_id);
$.ajax({
type: "GET",
url: 'http://website.com',
data: {action: filter, user_id: user_id},
success: function (result) {
$("#Target").html(result);
}
});
}
As you can see, the dropdown use the user_id and the option value to sort the results.
this code works only for 1 column, because he keeps (Ofcourse) using the first user_id. For example when I try to sort the second results, he sort the results of the first user_id (Normal).
I want that the SORT DROPDOWN use the user_id of the player is selected in the same column.
IMPORTANT
I want to use the sort option after showing both results on the page.