Merdok Posted May 18, 2009 Share Posted May 18, 2009 Hi Guys, This question is actually part PHP, Part MySQL and part AJAX so I hope I'm ok posting it in here, if not feel free to move it to its rightful home. Bascially, I've built an e-commerce site and the client wants the option to create product sets, whereby he can add a selection of products together to form one 'meta product'. I figured the best way of doing this would be to create an array called 'setItems[]' and the form to create new instances of 'setItems[]' whenever the user clicks on an 'add new product' link. This would then add item ID's to the array which will then be inserted into the DB... I presume this is the right way of doing it, the one place I'm kinda stuck on is the AJAX'y part, I've no idea on how to make the 'add new product' link create another form entry. I've used JQuery exactly once and even then it was basically cut'n'paste. Quote Link to comment https://forums.phpfreaks.com/topic/158570-solved-multiple-inserts-into-one-records/ Share on other sites More sharing options...
ohdang888 Posted May 18, 2009 Share Posted May 18, 2009 i don;t understand your problem...are the items being inserted into the database successfully? or is it JUST adding another element to the form thats throwing you off? Quote Link to comment https://forums.phpfreaks.com/topic/158570-solved-multiple-inserts-into-one-records/#findComment-836439 Share on other sites More sharing options...
Merdok Posted May 18, 2009 Author Share Posted May 18, 2009 Yeah its just adding another entry to the form, Thinking about it, that title wasnt really the best one to give was it Quote Link to comment https://forums.phpfreaks.com/topic/158570-solved-multiple-inserts-into-one-records/#findComment-836514 Share on other sites More sharing options...
Merdok Posted May 18, 2009 Author Share Posted May 18, 2009 Ok I've made some progress using jQuery but it is inserting the field at the bottom of the page rather than below the previous element like I want it to do. Here is the code: function addAnother() { jQuery('#addSetForm').append('<input type="text" name="setItems[]" id="setItems[]" />'); } Quote Link to comment https://forums.phpfreaks.com/topic/158570-solved-multiple-inserts-into-one-records/#findComment-836522 Share on other sites More sharing options...
ohdang888 Posted May 18, 2009 Share Posted May 18, 2009 so you want it to perform an ajax function, then add another element? Quote Link to comment https://forums.phpfreaks.com/topic/158570-solved-multiple-inserts-into-one-records/#findComment-836638 Share on other sites More sharing options...
Ken2k7 Posted May 18, 2009 Share Posted May 18, 2009 Merdok, There's nothing wrong with the jQuery. I would probably just check what #addSetForm element is and make sure that is the element you want to add the input. If it's adding to the bottom of the page, you probably don't want to add to #addSetForm but something else. In any case, please know that you should have only one ID per page so you'll have to change id="setItems[]" to something else. You can use a class like class="setItems" but IDs should be unique so if you have more than one on the same page, it's not good. Quote Link to comment https://forums.phpfreaks.com/topic/158570-solved-multiple-inserts-into-one-records/#findComment-836649 Share on other sites More sharing options...
Merdok Posted May 19, 2009 Author Share Posted May 19, 2009 Ah! Yeah that makes sense, it was appending the box to the end of the form, I added a named div around the box and it worked. Re: the form ID, I actually know that, clearly just a moment of stupidity, Thanks for pointing it out. Quote Link to comment https://forums.phpfreaks.com/topic/158570-solved-multiple-inserts-into-one-records/#findComment-837061 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.