ok, so I have a database consisting of two tables, products and suppliers.
All suppliers fill out the form, and their data is then stored in the supplier table, and the product table contains a list of all products, so when the supplier fills out the form, he can select as many products as I like using jQuery JSON and AJAX to get a list of all products and then fill in the drop-down list with all of them, which can then be cloned as many times as necessary.
The problem I'm sitting right now is how can I insert all the different products that the supplier selects into the supplier table, or I just have to talk about all the products that he selects for one supplier, for better normalization, since all the products has already?
I will use jQuery $ .ajax to send form data in JSON format to a waiting PHP file, which will then parse it and insert the data into the database.
Basically, I need to figure out how to link the data in the database in order to achieve the best normalization, and I need to figure out a way to insert a variable number of products into the supplier table or find a way to link many products that it chooses for one supplier.
I am very new to relational databases, so any advice on how to proceed next will be helpful, just like any other advice that you guys may have!
The jQuery code that I use to populate the clones and POST products that the provider selects:
$(document).ready(function() {
var count = 0;
$("span.remove").live('click', function(){
$(this).closest("div.container").fadeOut(400, function(){
$(this).remove();
$('#button').attr('disabled','');
});
});
$('#button').attr('disabled','');
$('#button').click(function(){
var count = $("#systems_wrapper > .container").size();
var lastID = $("#systems_wrapper > .container:last").attr('id');
var exploded = lastID.split("_");
var increment = Number(exploded[1])+1;
if(count >= 5){
$('#button').attr('disabled','disabled');
}else {
$('#button').attr('disabled','');
}
var test = $('#systems_0.container').clone().attr('id', 'system_' + increment).appendTo('#systems_wrapper');
test.children(':nth-child(2)').append('<span class="remove"></span>');
test.children(':nth-child(2)').children(':first').attr('id', 'mail_' + increment).attr('class','dropDowns').attr('onchange','test();');
});
$.getJSON("test_post.php", function(data){
$('#box').html('');
$.each(data, function(i, products) {
$('#box').append(
$('<option></option>').html(products.products)
);
});
});
});
function test(){
var sections = $('#systems_wrapper').find('.dropDowns');
var newArray = new Array();
sections.each(function(){
var id = $(this).attr('id');
var val = $(this).val();
var o = { 'id': id, 'value': val };
newArray.push(o);
});
alert(newArray);
$.ajax({
type: "POST",
url: "qwer.php",
dataType: 'json',
data: { json: JSON.stringify(newArray) }
});
}
Thanx in advance!