Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

141
Visualizações
How to get table data from a button click if every table is generated in a loop?

So i don't usually work with tables so i don't quite know how to extract the data from them, it might be something quite simple that i'm missing but going to the question, i have 3 tables generated from an array coming from sql (ignore the number of tables, assume that you don't know the exact number) and each table has an image, some strings and a button, my question is, how can i get the data from the table which the button was pressed and how can i distinguish it from the others?

//query the database
          $ns = 'SELECT * FROM produtos';

          $result = $conn-> query($ns);

          if($result->num_rows !=0) {
            $rowid = 0;
            while ($row = $result->fetch_assoc()) {
              $image = $row['nome_imagem'];
              $rowid += 1;
              $nome = str_replace('_', ' ', $row['nome_produto']);
              echo "<form><table style='border: 1px solid black; margin-left: 10px; width: 99%'>",
              "<tr class='$rowid'>",
              "<th style='border:1px solid black; width: 100px; height: 200px;'>", "<img src='./css/images/$image' width='200px' height='200px' alt='produto'/>", '</th>',
              "<th style='vertical-align: top; text-align: left; height: fit-content; width: 100%;'>", '<strong>'.$nome.'</strong>', "</th>",
              "<th style='border:10px solid black;'>", '<br>', '<br>', '<br>' , '<br>' , "<div class='buycont'>", "<button onclick='addcart()' class='buy' style='height: 50px; background-color: #ff7b00; vertical-align: bottom;'><strong> Buy <i href='#' class='bi bi-cart'> </i></strong> </button>", "</div>", "</th>",
              // "<td style='border:1px solid black; height: 10px'>", "ola" ,"</td>",
              "</tr>",
              "<tr style='border:1px solid black;'>",
              "<td>" .$row['valor']. '€', "<tr>" ,'<br>',
              "</tr>",
              "</table> </form>";
            }
            echo "<br>";
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda