close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

inserting multiple record using drop down

Thread began 1/27/2016 10:38 am by Kumel | Last modified 3/15/2016 10:02 am by Ray Borduin | 1916 views | 8 replies |

Kumel

inserting multiple record using drop down

Hi,
Lets say a product needs to be added & product got multiple categories. so from dropdown he chooses multiple categories.
But this multiple categories i want to be inserted in different table ei: CatProduct
It contains ID, ProductCatID, ProductID

ProductCatID will be category id choosen while adding product. & ProductID is current ProductID

Now when i choose multiple categories i want multiple records to be added in CatProduct table. But it isnt happening!
How can it be achieved?

Current when i test only one record is getting added in CatProduct.

If i choose 4 categories then 4 records must be added in CatProduct.

I choosed "insert multiple record" but isnt accepting it. (dw) even tho repeat region is added in multiple dropdown option!

Sign in to reply to this post

Ray BorduinWebAssist

If you set the name of the select list using brackets like: name="ProdCatID[]"

Then multi-selected values will automatically be submitted as an array. That way you can simply apply the insert for the CatProduct table and then manually add a FOR loop around it like:

php:
<?php

if (isset($_POST['ProdCatID'])) {
  for (
$x=0$x<sizeof($_POST['ProdCatID']); $x++)  {
?>
[YOUR INSERT CODE HERE]
<?php
  
}
}
?>


When you bind the column in the insert server behavior, set it to:

php:
<?php echo($_POST['ProdCatID'][$x]); ?>
Sign in to reply to this post
Did this help? Tips are appreciated...

Kumel

After making select name as "ProdCatID[]" .

then manually add a FOR loop around it like...?

I didnt understanding this. Does this require single record insert or multiple record inserts? Cos even after changing name i m not able to use multiple record inserts.

& what does [YOUR INSERT CODE HERE] means? which codes?

Sign in to reply to this post

Ray BorduinWebAssist

The for loop is in the code I showed you. There is no multiple record insert in mysqli currently. So it uses the single record insert with the manual for loop I've given an example of in the post above.

[Your insert code here] is where you would have the chunk of code you want to be repeated (insert server behavior)

Sign in to reply to this post
Did this help? Tips are appreciated...

Kumel

i added this. doesnt work. file attached.

Sign in to reply to this post

Kumel

its working.. there was a small change required.. So how about it edit page? will it work the same way?

Sign in to reply to this post

Ray BorduinWebAssist

The best bet on the edit page is to delete all of the rows for that record and then re-insert the ones selected with the same code... So you use the same insert code, just add the delete record code before it so that the old selections are effectively cleared out.

Sign in to reply to this post
Did this help? Tips are appreciated...

Kumel

delete all rows? reinsert the ones selected?
So delete all rows using hidden elements & have different form or within same new form?
How will we display already selected on select?
Place delete record trigger on submit button & before insert record?

Sign in to reply to this post

Ray BorduinWebAssist

You shouldn't need hidden elements to delete all rows... presumably they all share a master id that you can use to delete in one application of the delete server behavior.

Re-insert using the same logic as the insert page.

Re-selecting the previously selected would require:
1) create a recordset to get the selected values
2) loop through it and create an array of selected values
3) Use in_array() to check if the value was selected in the <option> tags

Yes, delete should use the same trigger and be added before the looped insert.

Sign in to reply to this post
Did this help? Tips are appreciated...

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...