1
\$\begingroup\$

Could anyone suggest a better approach than the one I'm using now? I tried to keep it as minimal as possible, but this is the best I came up with. I did extensive research just to get to this point.

baccarat.php echos a json_encoded PDO array.

function baccarat() {
  clearTimeout($.ghist);

  $.getJSON('/baccarat.php', function(data) {
    $.col = {};
    for (var n = 0; n <= 4; n++) {
      $.col[n] = '';
      $.each(data, function(i) {
        $.col[n] = '<select onchange="patatas(this.id,this.value)" class="testbigroad ' + data[i][n] + '-type" id="' + n + '-' + i + '"><option value="P" >P</option><option value="B">B</option><option value="T">T</option><option value=""></option></select>';
        $(".col-" + n + "-" + i).html($.col[n]);
        $(".col-" + n + "-" + i + " option:contains(" + data[i][n] + ")").prop('selected', true);
      });
    }
  });

  $.ghist = setTimeout(function() {
    baccarat();
  }, 5000);
}

function patatas(test, test2) {
  alert(test);
  $.ajax({
    url: "updatebaccarat.php",
    data: $.param({
      strid: test,
      strvalue: test2
    }),
    type: 'post',
    success: function(response) {
      baccarat();
    }
  });
}
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.