I have two tables. I want to achieve the show/hide for the sub rows. I can able to get corresponding main and sub row via php. for example
ID Field1 Field2
01 xxx xxx
01 yyy yyy
02 zzz zzz
02 abc abc
02 xyz xyz
Above table structure 01 xxx 02 zzz zzz are from table1 others are from table 2. I have buttons for each main rows. when I click the button the corresponding sub rows will appear. The problem is when I click the button the JS
returns only the first row. I'm stuck with that. help me
My PHP CODE:(SORRY for the huge code)
$connect = mysqli_connect('localhost', 'root', '', '');
$select1 =mysqli_query($connect,"SELECT * FROM ai");
while ($rownew=mysqli_fetch_array($select1))
{
?>
<input type='button' id="row_show_button<?php echo $rownew['idactionitems'];?>" value=<?php echo $rownew['idactionitems']?> onclick="ai_row_show_button('<?php echo $rownew['idactionitems'];?>');">
#some table datas here
</tr>
<?php
$new = mysqli_query($connect, "SELECT * FROM rowai WHERE idactionitemsFK =".$rownew['idactionitems']);
while($newrow1=mysqli_fetch_array($new))
{
?>
<tr style="display:" id="trhide<?php echo $newrow1['idactionitemsFK'];?>">
<td id="txt_name_edit1<?php echo $newrow1['idactionitemsFK'];?>"><?php echo $newrow1['idactionitemsFK'];?></td>
<td id="txt_name_edit2<?php echo $newrow1['idactionitemsFK'];?>"><?php echo $newrow1['row'];?></td>
</tr>
<?php
}
}
?>
JS CODE:
function ai_row_show_button(idactionitems) {
var trhide = document.getElementById("trhide"+idactionitems);
//alert (trhide);
if (trhide.style.display == "none") {
<?php
$newsc = mysqli_query($connect, "SELECT * FROM rowai WHERE idactionitemsFK = idactionitemsFK ");
#
while($newrow1=mysqli_fetch_array($newsc))
{
?>
trhide.style.display = "block";
<?php } ?>
} else {
trhide.style.display = "none";
}
}
The solution I'm looking for is when I click the button that is generated by the first table, The value of the button passed to the JS
function and give the all <tr>
which are in the second table that is matching with the ID. Currently I'm receiving first row only. Please help me