Skip to content

Dynamic textbox creation with db using ajax/javascript/php

I have two tables. company_details and company_specials. Each company_details can have multiple specials. I display the company details at

The first row and fourth row that has the 0 in the active column is from company_details and the rows below are from company_specials.

Currently the code allows for dynamic modification of the company_details rows as denoted by the compid in that table. However i would like to have the rows below it to be dynamically modified as well but it’s using the same compid and i’m not sure how to separate them in the code.

Code below is the code being generated for the company_specials. I need a way to uniquely identify each row and be able to modify it.

Could somebody provide some guidance please? I’m thinking that i would probably need to uniquely identify each of the specials within the company_specials or set some sort of pointers?


Add unique ids to your db tables and output hidden text fields with each record to indicate it table origin and its id. this will allow the code to know which table had which row updated or deleted. inserting new records can be accomplished by offering a blank record of each type at the end of each group, so there would be one blank specials record at the end of each group and one blank company record at the end of the table.

Put a unique name on each input field of the form name=’comp[<?php echo $comp_id?>][<?php echo $comp_field_name?>]’ and name=’spec[<?php echo $spec_id?>][<?php echo $spec_field_name?>]’ so that when the table is posted, PHP will see two arrays, $comp and $spec. You can loop over these with

foreach ($comp as $id=>$row)

and loop over each $row to build an SQL update or insert statement with

foreach ($row as $fld=>$val)