Php Extracting items from a list

Asked

Viewed 38 times

0

How do I stop removing items from a <table> using php.?

the situation is as follows:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"url_onde_pego_os_dados");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result=curl_exec ($ch);

in case $result is a <table> with the items I want to extract.

example

<tr class="primeiroregistro">
             <td align="left">ABC</td>
             <td align="left">Atol ABC  </td>
             <td align="left">Plastico</td>
             <td align="right">13,45</td>
             <td align="right">13,01</td>
             <td align="right">13,65</td>
             <td align="right">13,27</td>
             <td align="right">13,28</td>
             <td align="right">-1,26%</td>
             <td align="right">13,25</td>
             <td align="right">13,28</td>
             <td align="right">1.368</td>
             <td align="right">506.500</td>
           </tr>

1 answer

0

Add the following code to your table so you have a source of disoaro to pick up your current line (the one that is clicked).

<td>
   <button type="button"
           onclick="pegarEssaLinha(this)">
      Pegue esta Linha
   </button>
</td>

Now in Javascript put this function, because it will be triggered at the click of the table.

function pegarEssaLinha(elemento) {
    // Linha atual
    var linhaAtual = $(elemento).closest("tr");
    // Celulas
    var coluna0 = linhaAtual.find("td:eq(0)").text().trim();

    window.alert(colunaID);
}

Note that the section where you have >>> td:eq(0) <<< is the part that takes the value of the first column of the TD of the Line where the button was triggered. To take the other values change 0 by the desired column number.

I particularly never used these Curl functions, so if I were to send to register Mandaria via Ajax.

function pegarEssaLinha(elemento) {
   // Linha atual
   var linhaAtual = $(elemento).closest("tr");
   // Celulas
   var nParametros = {};
   nParametros.coluna0 = linhaAtual.find("td:eq(0)").text().trim();
   nParametros.coluna1 = linhaAtual.find("td:eq(1)").text().trim();
   nParametros.coluna2 = linhaAtual.find("td:eq(2)").text().trim();
   nParametros.coluna3 = linhaAtual.find("td:eq(3)").text().trim();
   nParametros.coluna4 = linhaAtual.find("td:eq(4)").text().trim();
   nParametros.coluna5 = linhaAtual.find("td:eq(5)").text().trim();
   nParametros.coluna6 = linhaAtual.find("td:eq(6)").text().trim();
   nParametros.coluna7 = linhaAtual.find("td:eq(7)").text().trim();
   nParametros.coluna8 = linhaAtual.find("td:eq(8)").text().trim();
   nParametros.coluna9 = linhaAtual.find("td:eq(9)").text().trim();
   nParametros.coluna10 = linhaAtual.find("td:eq(10)").text().trim();
   nParametros.coluna11 = linhaAtual.find("td:eq(11)").text().trim();
   nParametros.coluna12 = linhaAtual.find("td:eq(12)").text().trim();
   // Envia os dados para o servidor.
   $.post("url_onde_pego_os_dados", nParametros, function (resposta) {
       window.alert(resposta);
   });
}

Take this data by retrieving the super global $_POST["coluna0"] and so for a day one by one there on the server. Since I don’t know what you need to do, I’m gonna stop here and not make it too complicated.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.