Each or next from a MySQL query

1

How to post the next item in a MySQL multi-item query?

When changing $( ".membro" ).change(function() { , send the data of the next $("membro") to the file membros.php , via $.post .

JSFIddle

JS:

$(".membro").change(function () {    
    $.post("membros.php", {
        mes: $(".mes").val(),
        ano: $(".ano").val(),
        celula: $(".celulanome").val(),
        membro: $(".membro").val()
    });    
});

HTML

<tr class=\"tabl\">
    <td id=\"tabela2\" class=\"id\">$row[posicao]
    </td>
    <td id=\"tabela4a\">
    <input type=\"hidden\"  class=\"celulanome\" name=\"membro\" value=\"$celula\">
    <input type=\"hidden\"  class=\"mes\" name=\"membro\" value=\"$mes\">
    <input type=\"hidden\"  class=\"ano\" name=\"membro\" value=\"$ano\">
    <input type=\"text\"  class=\"membro\" name=\"membro\" value=\"$row[membro]\">
    </td>
</tr>


<tr class=\"tabl\">
    <td id=\"tabela2b\" class=\"id2\">$row[posicao]
    </td>
    <td id=\"tabela4b\">
    <input type=\"hidden\"  class=\"celulanome\" name=\"membro\" value=\"$celula\">
    <input type=\"hidden\"  class=\"mes\" name=\"membro\" value=\"$mes\">
    <input type=\"hidden\"  class=\"ano\" name=\"membro\" value=\"$ano\">
    <input type=\"text\"  class=\"membro\" name=\"membro\" value=\"$row[membro]\">
    </td>
</tr>


<tr class=\"tabl\">
    <td id=\"tabela2c\" class=\"id3\">$row[posicao]
    </td>
    <td id=\"tabela4c\">
    <input type=\"hidden\"  class=\"celulanome\" name=\"membro\" value=\"$celula\">
    <input type=\"hidden\"  class=\"mes\" name=\"membro\" value=\"$mes\">
    <input type=\"hidden\"  class=\"ano\" name=\"membro\" value=\"$ano\">
    <input type=\"text\"  class=\"membro\" name=\"membro\" value=\"$row[membro]\">
    </td>
</tr>

PHP

<?php    
include "bd_connect.php";

$membro=$_POST['membro'];    
$celula=$_POST['celula'];
$mes=$_POST['mes'];
$ano=$_POST['ano'];
$posicao=$_POST['posicao'];

if (isset($membro))
{
   $query = mysql_query("UPDATE contas2 SET membro='$membro' WHERE mes LIKE '$mes' AND ano LIKE '$ano' AND celula LIKE '$celula'") or die(mysql_error());
}
?>
    
asked by anonymous 20.07.2014 / 23:03

2 answers

2

Test like this:

$(".membro").change(function () {
    var proximoMembro = $(this).closest('tr').next().find('.membro');
    $.post("membros.php", {
        mes: $(".mes").val(),
        ano: $(".ano").val(),
        celula: $(".celulanome").val(),
        membro: proximoMembro.val()
    });

});

The idea is:

  • $(this) starting point, the "member" that has changed
  • .closest('tr') search by ascending on the DOM tree the first tr
  • .next() go to next tr
  • .find('.membro'); descend / search within this line the element with class .membro
20.07.2014 / 23:29
0

I was able to use each and find !!!

Code:

$(".membro").change(function () {
$('.tabl').each(function() {
var proximoMembro = $(this).find( ".membro" ).val();

    $.post("membros.php", {
        mes: $(".mes").val(),
        ano: $(".ano").val(),
        celula: $(".celulanome").val(),
        membro: proximoMembro
    });

});
});
    
21.07.2014 / 18:43