Note that there are some explanatory texts on larger screens.

plurals
  1. POBuild json to send to php using a for loop (maybe)
    text
    copied!<p>I've googled around, but i can find a way to build json with jQuery and send it to php using a for loop. I have a html table, and i want to take values from each row (i dont know how many rows/values there will be) construct a json string, ie. <code>[{"row": 1, "supp_short_code" : blah blah....}, {"row": 2, ....} ....] </code> but i dont know how to keep adding to the json datastring each time jQuery finds more values if that makes sense??</p> <p>EDIT:</p> <p>So if i have this </p> <pre><code>$('#submit').live('click',function(){ var supp_short_code=$('.supp_short_code').text(); var project_ref=$('.project_ref').text(); var om_part_no=$('.om_part_no').text(); var description=$('.description').text(); var cost_of_items=$('.cost_of_items').text(); var cost_total=$('.cost_total').text(); var dataString = 'string=//' + supp_short_code + '//' + project_ref + '//' + om_part_no + '//' + description + '//' + cost_of_items + '//' + cost_total $.ajax ({ type: "POST", url: "order.php", data: dataString, cache: false, success: function() { alert("Order Submitted"); } }); }); </code></pre> <p>So what (roughly) would i need to change in this code? <img src="https://i.stack.imgur.com/X9u0r.png" alt="Screenshot"></p> <p>Ok, so as you can see by the screenshot, i'm using jquery to dynamically add the bottom table when a user click a row from the top table, its calculating totals and they can specify which supplier they want to use. I'm then using jquery to grab these values into the $('submit') bit of jquery code at the top. I then want to send these values to a php page that will somehow parse the received data at insert it into a mysql db, as something like "id 1 product blah price blah supplier blah total cost £x, id 2 product blah2 price blah2 supplier blah total cost £x" so some fields, ie the total cost and supplier will be the same, but the php might be receiving 3 different products for the same order if that makes sense? Thanks!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload