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

110
Views
Expandable table

I want to make expandable table like this expandable table filled by PHP script. Now it doesn't work after i added if statement in hidden.foreach(). Do You know why it doesn't work and how to fix this problem ?

echo "<table><thead><th>Product</th><th>Expenses</th><th>Group</th><th>Show more</th></thead>";
    while($row=$show_costs->fetch_assoc())
    {
        $show_more_costs=$conn->query("SELECT `name`,`describtion`,`cost`,`b_date`,`group` FROM `costs` WHERE `pId`='".$row['pId']."'");
        echo "<tr><td>".$row['pId']."</td><td>".$row['costs']."</td><td>".$$row['group']."</td><td><span id='show_more'>▼</span></td></tr>";
        //Detailed costs which i want to expand after clicking this
        while($row_md=$show_more_costs->fetch_assoc())
        {
            echo "<tr class='hidden'><td>".$row_md['name']."</td><td>".$row_md['describtion']."</td><td>".$row_md['cost']."</td><td>".$row_md['b_date']."</td><td>".$row_md['group']."</td></tr>";
        }
    }
    echo "</table>";

//This is my JS code:

show_more=document.querySelectorAll('#show_more');
hidden=document.querySelectorAll('.hidden');
show_more.forEach(show_more =>{
  show_more.addEventListener('click',event=>{
    hidden.forEach(hidden=>{
      if(hidden.style.display==='none')
      {
        hidden.style.display='table-row';
      }
      if(hidden.style.display==='table-row')
      {
        h1.style.display='none';
      }
    })
  })
})

What do I have to fix?

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!