Mam następujący problem.
Nie jestem dobry w ajaxie, ale potrzebuje zrobić auto update po opuszczeniu danego inputa.
Byłoby okej, tylko, że muszę do mieć (tak jakby w pętli) bo każde pole osobno będzie zapisywane.
Problem w tym, że gdy zacząłem to testować, to updatuje mi do bazy, ale pod wszystkie inne rekordy, a ten, który potrzebuje ma wartość 0.
Powinno być, że updatuje tylko żądany rekord. Jak to rozwiązać ?
Pomoże ktoś ?
KOD:
while($docs_ed=mysql_fetch_array($res_doc)){
$result_art = mysql_query("SELECT * FROM products WHERE id='$docs_ed[id_art]'");
$dane_art=mysql_fetch_array($result_art);
?>
<script type="text/javascript">
$('input[name=r35]').blur(function() {
var r35 = $(this).val();
var id = "
<? echo $dane_art[id
]; ?>";
var docs = "
<? echo $dane_doc[doc
]; ?>";
var iddocs = "
<? echo $_GET[edit
]; ?>";
$.ajax({
url: "docajax3.php",
type: "POST",
data: 'update35=' + r35 + '&idart=' + id + '&nrdok=' + docs + '&idok=' + iddocs,
success: function(msg) {
$("#kontener3").html(msg);
}
});
});
</script>
<?
<tr>
<td align="center">'.$docs_ed[symbol_art].' </td>
<td align="left"><b style="font-size:12px;">'.$dane_art[nazwa].'</b> <br> ';
if ($dane_art[tab_rozm_id] == '1'){
35 <input class="sf_small_1" name="r35" id="r35" maxlength="3" value="'.$docs_ed[r35].'" type="text"/>
36 <input class="sf_small_1" name="r36" id="r36" maxlength="3" type="text"/>
37 <input class="sf_small_1" name="r37" id="r37" maxlength="3" type="text"/>
38 <input class="sf_small_1" name="r38" id="r38" maxlength="3" type="text"/>
39 <input class="sf_small_1" name="r39" id="r39" maxlength="3" type="text"/>
40 <input class="sf_small_1" name="r40" id="r40" maxlength="3" type="text"/>
41 <input class="sf_small_1" name="r41" id="r41" maxlength="3" type="text"/>
42 <input class="sf_small_1" name="r42" id="r42" maxlength="3" type="text"/>
43 <input class="sf_small_1" name="r43" id="r43" maxlength="3" type="text"/>
44 <input class="sf_small_1" name="r44" id="r44" maxlength="3" type="text"/><br>
45 <input class="sf_small_1" name="r45" id="r45" maxlength="3" type="text"/>
46 <input class="sf_small_1" name="r46" id="r46" maxlength="3" type="text"/>
47 <input class="sf_small_1" name="r47" id="r47" maxlength="3" type="text"/>
48 <input class="sf_small_1" name="r48" id="r48" maxlength="3" type="text"/>
</tr> ';
}
}
PLIK doajax3.php:
<?php
require_once ('../pages/db2014.php'); // Połącz się z bazą danych.
if($_POST['update35'] != '') {
$id = $_POST['idart'];
$nrdok = $_POST['nrdok'];
$r35 = $_POST['update35'];
$idok = $_POST['idok'];
$dodaj = mysql_query("UPDATE $nrdok SET r35 = '$r35' WHERE id_art='$id'");
echo'<center><font color="green" size="3">Update pomyślnie <br><br>id: '.$id.' | doc: '.$nrdok.' | szt: '.$r35.' </font>
<a href="index.php?page=documents&edit='.$idok.'"> <button type="button" class="btn btn-warning"><i class="icon-refresh"></i> Odśwież dokument</button></a>
</center><br><br>';
}
?>
A może ktoś mi podpowie prostsze i łatwiejsze rozwiązanie ?
Ten post edytował denis95x 25.02.2015, 08:37:40