0
I have a Datatable here and I’m using a plugin so that the user can edit the table data, got in parts(haha), the problem is that my call is not identifying what the user enters, and when I manually set the cell value it changes in all rows of that column in db, I imagine I need to identify the row ID the user is editing but I don’t know how to do.
Below my Ajax Call:
$.ajax({
url: "include/edita.php",
type: "POST",
data: { 'coletadora': 'Definição Manual'},
success: function(data){
alert(data);
}
});
It is also relevant the content of my edita.php (ignore the defamed php, was long away from php and need this system running before transitioning to PDO), I know I need a WHERE to limit the update to this particular ID that we will discover:
<?php
$host= 'localhost';
$bd= 'minhadb';
$userbd = 'meuusr';
$senhabd= 'meupw';
//Conectando com banco MySQL
$conexao = mysql_connect($host,$userbd,$senhabd);
if (!$conexao)
die ("Erro de conexão com localhost, o seguinte erro ocorreu -> ".mysql_error());
//Conectando com a tabela do banco de dados
$banco = mysql_select_db($bd,$conexao);
if (!$banco)
die ("Erro de conexão com banco de dados, o seguinte erro ocorreu -> ".mysql_error());
$coletadora = $_POST["coletadora"];
$sql = "UPDATE minhadb SET coletadora = '$coletadora'";
mysql_query($sql,$conexao);
?>
Thanks in advance for the help!
The logic of the process I had in mind, the difficulty in applying is in the fact that this Datatable is generated from a SELECT in my db, so I can not hit the syntax of jquery to capture the ID of the line I am editing. What can help me is the fact that the line id is shown as "Protocol" for the user to query after scheduling, it was a shortcut I took, but I do not know how to use this in my favor, if it is necessary.
– Fernando Gross
Take a look at how the table @victormoraesgs : http://pasted.co/ed579cd4
– Fernando Gross
@Fernandogross You can place $Row['id'] as a property of every td of that line.
– victormoraesgs
@Fernandogross another possibility that I thought about now, is to give a name to each <td> with its respective column,
<td name="id">$row['id']</td>
, this makes it possible for you to select that cell from the edited cell:$('tdEdidata').siblings('td[name="id"]').text();
this would bring the id of that line to your AJAX request.– victormoraesgs
Ex: http://pasted.co/1c770c6f
– victormoraesgs
Opa, in your first example I had the idea to do after your first answer yesterday, I just did not know how Ajax is so that the user can change the cells Collector, Date Collection and Time Collection only for the id of the Row that he selected, I think that’s all that’s missing. Already in your code the problem was that it was all out of order the table, not respecting the order of th, with some study can order,
– Fernando Gross
Code of the amendment I had made: http://pasted.co/66b90f36
– Fernando Gross
@Fernandogross The only problem with your example is how you named the tags, for example: <td id="collector".... The id of an element must be unique, so you cannot use the collecting id for several different cells (since it has several lines). Answer me this, how will you edit your chart? There is a centralized Save button that saves all lines or a save button per line?
– victormoraesgs
Look at the Ajax call as it is now: http://pasted.co/43edc2f8 It sends everything as you can see.
– Fernando Gross
The moment the user clicks on the cell he wants to edit, he opens a field to enter the new value, with a button to confirm and another to cancel, he can click on more than one cell at the same time (another field opens to each editable cell clicked), as we could see in Firebug even though he click "confirm" in a single cell it sends the data of all cells that I determined editable, I imagine that if the user did not change a cell that opened it sends the current cell data.
– Fernando Gross