Pegar vários valores com Foreach via ajax
Olá pessoal,
Poderiam me ajudar?
Preciso enviar o formulário via ajax, porém preciso pegar todos os valor de todos os inputs e excluir o valor de cada linha em três tabela.
Pode ser que alguma tabela não tenha nenhum valor, mas tem tabela que pode ter 10 valores.
Tentei fazer como estou enviando, mas não consegui...
Obrigado!
<form name='formResiduo'>
<?php
$sqlr_end = "SELECT e.idclie FROM tb_end e WHERE NOT EXISTS(SELECT i.idinc FROM tb_inc i WHERE e.idclie = i.idinc) ORDER BY e.idclie ASC";
$querye = $conn->query($sqlr_end);
$linhas = $querye->num_rows;
while($rowrend = $querye->fetch_assoc()) {
$reidclie = $rowrend["idclie"];
if ($linhas == "0") { $linhase = ""; } else { $linhase = $linhas; }
?>
<input type='text' name='valor[]' value='<?php echo $reidclie; ?>'>
<?php } ?>
<?php if ($linhase) { ?>
<div class='emCursorD emBlkA' style='position:relative;font-size:14px;font-weight:300;'>
<div style='position:absolute;width:calc(100% + 100px);height:100%;left:-10px;'></div>
<div class='formImptG' style='border-radius:3px;padding:5px;margin-bottom:20px;'>
<label>
<div style='position:relative;border-bottom:1px solid #606060;padding-top:10px;margint-top:5px;'><?php echo $linhase; ?></div>
</label>
</div>
</div>
<?php } ?>
<?php
$sqlr_res = "SELECT r.idclir FROM tb_res r WHERE NOT EXISTS(SELECT i.idinc FROM tb_inc i WHERE r.idclir = i.idinc) ORDER BY r.idclir ASC";
$queryr = $conn->query($sqlr_res);
$linhas = $queryr->num_rows;while($rowrres = $queryr->fetch_assoc()) {
$rridclir = $rowrres["idclir"];
if ($linhas == "0") { $linhasr = ""; } else { $linhasr = $linhas; }
?>
<input type='text' name='valor[]' value='<?php echo $rridclir; ?>'>
<?php } ?>
<?php if ($linhasr) { ?>
<div class='emCursorD emBlkA' style='position:relative;font-size:14px;font-weight:300;'>
<div style='position:absolute;width:calc(100% + 100px);height:100%;left:-10px;'></div>
<div class='formImptG' style='border-radius:3px;padding:5px;margin-bottom:20px;'>
<label>
<div style='position:relative;border-bottom:1px solid #606060;padding-top:10px;margint-top:5px;'><?php echo $linhasr; ?></div>
</label>
</div>
</div>
<?php } ?>
<?php
$sqlr_his = "SELECT h.idclih FROM tb_his h WHERE NOT EXISTS(SELECT i.idinc FROM tb_inc i WHERE h.idclih = i.idinc) ORDER BY h.idclih ASC";
$queryh = $conn->query($sqlr_his);
$linhas = $queryh->num_rows;while($rowrhis = $queryh->fetch_assoc()) {
$rhidclih = $rowrres["idclih"];
if ($linhas == "0") { $linhash = ""; } else { $linhash = $linhas; }
?>
<input type='text' name='valor[]' value='<?php echo $rhidclih; ?>'>
<?php } ?>
<?php if ($linhash) { ?>
<div class='emCursorD emBlkA' style='position:relative;font-size:14px;font-weight:300;'>
<div style='position:absolute;width:calc(100% + 100px);height:100%;left:-10px;'></div>
<div class='formImptG' style='border-radius:3px;padding:5px;margin-bottom:20px;'>
<label>
<div style='position:relative;border-bottom:1px solid #606060;padding-top:10px;margint-top:5px;'><?php echo $linhash; ?></div>
</label>
</div>
</div>
<?php } ?>
</form>
<div class='passar emLineB emCursorP'>Passar</div>
<script>
$(document).ready(function() {
$('.passar').click(function(passar) {
var formdata = new FormData($("form[name='formResiduo']")[0]);
var link = 'sys/incClient.php?teste=ex';$.ajax({
dataType: 'json',
type: 'POST',
url: link,
data: formdata,
processData: false,
contentType: false,
success: function (result) {
var data = result.split('|');
var rA = data[0];
var rB = data[1];
if(rA == "sucesso") {
alert(rB);
}
return false;
}
});
});
});
</script>
if($_GET['teste']=="ex") {
foreach($_POST['valor'] AS $lines) {
$sqlr = @mysqli_query($conn, "DELETE FROM tb_res WHERE idclir = '$lines'");
$sqle = @mysqli_query($conn, "DELETE FROM tb_end WHERE idclie = '$lines'");
$sqlh = @mysqli_query($conn, "DELETE FROM tb_his WHERE idclih = '$lines'");
}
$arrch = "sucesso"."|".$lines;
echo json_encode($arrch);
exit;
}Discussão (0)
Carregando comentários...