php - Get data from a table line and pass it to a form -


I am saying in initial PHP / HTML / JAVASCRIPT code and I have problems working on table "edit" It's okay, I hope you guys can help me!

Here's the story: I am creating a Bootstrap Table, and to get data from a database and to create new rows for each row in the archive. For loop also creates a button called 'edited' (from Bootstrap) and when I click on this button I am using jQuery to show a model with a form, which is in a div.

My problem is, how can I populate the mode of division (using value = "") according to the table on which the user clicked?

Code:

  & lt; Table class = "table-table-conditioned table-stripe" & gt; & Lt; TR & gt; & Lt; Width = "20%" & gt; Nom Fullo & lt; / Th & gt; & Lt; Th & gt; Telephone Residencell & lt; / Th & gt; & Lt; Th & gt; Telephone cellular & lt; / Th & gt; & Lt; Th & gt; Bairro & lt; / Th & gt; & Lt; Th & gt; Endereco & lt; / Th & gt; & Lt; Th & gt; Complemento & lt; / Th & gt; & Lt; Th & gt; & Lt; / Th & gt; & Lt; / TR & gt; & Lt ;? Php required ("config / connection.inc.php"); $ Client = R: all found ("select from client"); Foreign Currency ($ client $ as client) {? & Gt; & Lt; TR & gt; & Lt; TD & gt; & Lt ;? = $ Customer ['Something'] & gt; & Lt; / TD & gt; & Lt; TD & gt; & Lt ;? = $ Customer ['Something'] & gt; & Lt; / TD & gt; & Lt; TD & gt; & Lt ;? = $ Customer ['Something'] & gt; & Lt; / TD & gt; & Lt; TD & gt; & Lt ;? = $ Customer ['Something'] & gt; & Lt; / TD & gt; & Lt; TD & gt; & Lt ;! --- How can I click on the client's ID and send it to the Div form of the model? --- & gt; & Lt; Button class = "btn btn-information btn-sm" name = "edit" & gt; Edit & lt; / Button & gt; & Lt; / TD & gt; & Lt; / TR & gt; & Lt ;? Php}? & Gt; & Lt; / Table & gt; & Lt ;! ------ DIV of the model ("ALTER BUTTON") ------ & gt; & Lt; Div id = "basic-modal-content" & gt; & Lt; Div id = "titulo" & gt; & Lt; P & gt; Edit & lt; / P & gt; & Lt; / Div & gt; & Lt ;! ---- I would like to populate this form on the database! ---- & gt; & Lt ;! ---- But I need at least an ID from the table's clicked line so that I can make the PHP request to the database and get the right data! ---- & gt; & Lt; Form style = "margin-left: 50px;" & Gt; & Lt; Input type = "text" name = "something" /> & Lt; Input type = "text" name = "something" /> & Lt; Input type = "text" name = "something" /> & Lt; Input type = "submit" name = "btneler" value = "altarar" class = "btn btn-information btn-sm" /> & Lt; / Form & gt; & Lt; / Div & gt; & Lt ;! - this model --- & gt; There is some jquery for opening & lt; Script & gt; $ ('[Name = "Edit]]. (Function () {$ (" # basic-modal-content "). Modal ();}); & lt; / script & gt;  

Thank you very much! I agree that the question is a bit confusing, but hope you guys can understand it.

On the click event you can create a data object that is relevant to the client ID that you just click, a normal line will look like this ...

  Lt; tr data-line = "id_from_db">  & l T;? = $ Client ['something']? & Gt;  & lt; td name = "name2" & gt; & lt;? = $ Client ['something']? & Gt ; & Lt; / td & gt; & lt; td name = "name3">  ['some']? & Gt; Name = "name4"> gt; & lt;? = $ Client ['something']? & Gt; & lt; / td> & lt; td & gt; & lt ;; --- let me client How can the ID be clicked and send to the Div form of the model ?? -> & gt; & lt; button class = "btn btn-info btn-sm" name = "edit" data-record = " Id_from_db "& gt; Edit & lt; / Button & gt; & Lt; / TD & gt; & Lt; / TR & gt;  

Then in your click event, you can proceed to get the recorded data and apply the data prepared in your form before opening ...

  & lt; Script & gt; $ ('[Name = "Edit]]. (Function () {var recordan = $ (this) .attr (" data-record "); var data = getDataFromTable (recordno); populateModalForm (data); $ ("#info-modal-content"). Modal ();}) function getDataFromTable (recordno) {var data = {} $ ("[data-line =" + recordo + "] TD"). () {Data [$ (this) .attr ("name")] = $ (this) .html ();}); return data;} function populateFormData (data) {// select all input elements with name attribute Do $ ("#boot-modal-content [name]"). Each (function () {$ (this) .val (d) Ta [$ (this) .name ()]);}}}}   

You need to make sure that the name is correct in the table row The input name is mapped as.

Hope it helps!


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -