php - jQuery AJAX POST to mysql table for dynamic table data- Am I doing this in anything like the right way? -


I have a table that I can dynamically add and remove any number of rows. After the data is entered, I am using jQuery's AJAX functionality to post it in a mysql database, so that no page is redirected or refreshed.

The only way I could think of working on it, was using it for loop in jQuery, how dirty it is to post each line separately to the database? Should I get all the table data and post it once? Different rows can be different on user and users can add and delete as many likes before submitting them.

Strange I have the variable count count due to having two rows at the top of the table. I could not do a great way of doing this.

I always went crazy about the data related to the correct line

Thank you for your time. Click here (function () {// process form var rowCount = jQuery ('# dataTable tr'). ; (Var i = 2; i & lt; rowCount; i ++) {// I am storing four elements of each row on mysql var txtRow1 = jQuery ('# txtRow' + (i-1)). (); Var TickerRow1 = jQuery ('# tickerRow' + (i-1)) Val (); var quantrav 1 = jQuery ('# quintro' + (i-1)). Val (); var valueRow1 = jQuery ('# ValueRow' + (I-1)). Val (); var Data String = 'txtRow1 =' + txtRow1 + '& Tickerwave 1 =' + Tickerau 1 + '& amp; quantRow1 =' + Volume 1 + '& Amp; Mono = 1' + MONO 1; / / Warning (Datasar ;) Return false; jQuery.ajax ({type: "post", url: "http://rccl.co.uk/form_action1.php", data: datastring});}; return back;});} );

It looks very clearly for me as if you have a well The established index is the query in the row, most of the form handlers using the variable i will open the repeated key of server-side form in a list, such as several checkboxes with the same name. You could take advantage of it here.

  datastring = ''; (Var i = 2; i & lt; rowCount; i ++) for {var txtRow1 = jQuery ('# txtRow' + (i-1)). Val (); Var tickerRow1 = jQuery ('# ticker rau' + (i-1)). Val (); Var quantRow1 = jQuery ('# quantRow' + (i-1)). Val (); Var valueRow1 = jQuery ('# valueRow' + (i-1)). Val (); Datastring = datastring + 'index [] =' + (i-1) + 'txtrow1 [] =' + txtrow1 + 'and tikrarov 1 [] =' + tickerro 1 + 'and quantovo 1 [] =' + quantarrao 1 + '& Amp; ; ValueRow1 [] = '+ valueRow1; }   

Then call Ajax with the whole string.

On the server side, you should get the array for each of these, each of which corresponds to the first first line, each of which corresponds to the second row, and so on.

Since the time I use PHP, it has been a long time since, but I believe that [] symbols for each key item in PHP < It is necessary for the code> $ _ POST sign to convert the contents of different keys into arrays.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -