DMXzone Database Updater PHP Support Product Page

How do I insert a dynamic record into another table?

Asked 21 May 2015 23:23:18
1
has this question
21 May 2015 23:23:18 Brent Metzker posted:
I am trying to build a dynamically populated table to be able to add the results to another table which will be a shopping cart. I can get the fields into the cart table but it only uses the top value on the search list. Also, I have a "quantity" field but it only loads the value "1" even if I type in a different number. I can populate the table from a form just fine so I'm not sure where I am going wrong.

Replies

Replied 22 May 2015 07:36:58
22 May 2015 07:36:58 Teodor Kuduschiev replied:
Hello Brent,
Could you please be a little more detailed? What exactly are you trying to achieve?
Replied 22 May 2015 15:31:24
22 May 2015 15:31:24 Brent Metzker replied:
I have a database table that is searchable by a part number field (contains). I have put the results inside of a form and have added a "add to cart" button with a behavior of "Control DMX database executor". I want the customer to be able to go through and pick the item that they want from the search results and click on the "add to cart" button beside that item and the item details would be added to another table I created called "orders" But it does not matter which button they click only the first search result is added to the table. And my text box for the quantity always shows "1" no matter what I change the value to. Make sense? I have not uploaded the page yet but I could if you need me to. I'm just testing on localhost.
Replied 25 May 2015 10:32:11
25 May 2015 10:32:11 Teodor Kuduschiev replied:
Hello Brent,
Please upload your page to some testing server, where we can access it.
Replied 26 May 2015 22:48:11
26 May 2015 22:48:11 Brent Metzker replied:
Hi, I have uploaded it to this location for testing. www.superbee.ca/jobber/ You will need to log in with a user name of dmxzone and a password of dmxzone. If you go the the "search by part number" link and search "INJ:" would be a good example. It won't matter which item you try to add to the databse it will alwatys add the top item in the search field and it also won't matter if you leave the "quantity" text field empty or what number you put in it it will always add a value of "1". You can check the database on the "Add to order" link (where you can also manually add an item to the database as well. I just set that up to test it.
Thanks for looking.
Replied 27 May 2015 06:50:27
27 May 2015 06:50:27 Teodor Kuduschiev replied:
Hi Brent,
First of all there is a problem with the database action:
Because of a wrongly selected data element you are inserting
"partnumber": "{{bynumber.data[0].number}}" -> which indeed adds the first element of the repeat region. Please open the database action and make sure to correctly select it. It should be something like {{number}} instead.
Then - the text field you are using to repeat on your page, has the same name and id in the repeat region. This means that after the page is rendered, you end up with 25 form fields on the same page. This is a problem because:
- The HTML markup does not allow you to use the same ID for different elements on your page
- The insert record uses this ID to insert the quantity and as there are 25 fields with the same ID on the page, the insert goes wrong.

Replied 28 May 2015 03:35:42
28 May 2015 03:35:42 Brent Metzker replied:
Hi Ted,
I understand what you are saying. The {{number}} element was inserted that way because I was using a combination of two tables so I will manually code that in the future.
And I understand what you mean about the form field but I don't know what to do to correct it. If I have to use another page to send my values to and then add the quantity I could but I would rather be able to do it all on one page. Do you have any suggestions? Could I use a html5 behavior of "on key down" Select active record? Would that work? Or is there an easier solution?
Thanks for your help.
Replied 28 May 2015 07:25:20
28 May 2015 07:25:20 Teodor Kuduschiev replied:
You shouldn't actually hand code the {{number}} it should be selected properly when you assign the database action executor to the button - just select "data override" and then add the property again, this will add it as:
{{number}} instead of {{bynumber.data[0].number}}

The best you can do on this page is to leave the repeat region with the products as it is, and to just remove the buttons and form fields. Make the table rows clickable.
Then add a Detail Region (below or above the table) that shows info about the selected record. Show it when someone clicks any of the products (rows).
In the detail region place the Add To Card button and the quantity field. Apply the database action to them.
Replied 13 Jun 2015 18:52:48
13 Jun 2015 18:52:48 Brent Metzker replied:
You mention that "You shouldn't actually hand code the {{number}} it should be selected properly when you assign the database action executor to the button" but I am not using an executor, just a search on a data source using a table Join. There is no option for "data override" When I use a table join the data always shows as {{bynumber.data[0].number}} format instead of just {{number}}. Then it repeats the first selection instead of showing all the results.
Am I totally missing something here?

Reply to this topic