Skip to content Skip to sidebar Skip to footer

Iterate And Get Unique Values From Json For Some Indexes

I'm getting data back from my PHP using a query like this: SELECT objective,signal_type,signal_name FROM signals WHERE channel='Email' The data comes back like this: [ {

Solution 1:

Check if the value is used before. If so print a blank string, if not print the new value.

This translates to your appending code:

storedObjective = "";
storedSignal_type = "";
$.each(data, function(index, key) {

    if (key.objective == storedObjective)
    {
        print_1 = "";
    }
    else
    {
        print_1 = objective;
        storedObjective = key.objective;
    }
    if (key.signal_type == storedSignal_type)
    {
        print_2 = "";
    }
    else
    {
        print_2 = key.signal_type;
        storedSignal_type = key.signal_type;
    } 

  $('#myTable').append('<tr><td>'+print_1+'</td><td>'+print_2+'</td><td>'+key.signal_name+'</td></tr>');
});   

Post a Comment for "Iterate And Get Unique Values From Json For Some Indexes"