Question

I have a grid like this http://jqueryui.com/demos/selectable/#display-grid .

How can I store a user selected "number" into mysql db using php ?

here is jquery selectable demo html code

Was it helpful?

Solution

Something like, will save the selectednumbers each time the selection changes:

Javascript side:

$( "#selectable" ).selectable({
        stop: function() {
            var selectedNumbers = "";
            $( ".ui-selected", this ).each(function(i) {
                if(i != 0) {
                    selectedNumbers += ",";
                 }
                 selectedNumbers += $(this).text();
            });
            $.ajax({
                type : "POST",
                url: "savenumbers.php",
                 data : {
                     numbers: selectedNumbers
                  }
            });
         }
    });

PHP (really simple example)

$numbers = mysql_real_escape_string($_POST['numbers']);
mysql_query("INSERT INTO mytablename (numbers) VALUES('" . $numbers . "')");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top