Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

134
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!