Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

138
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda