简体   繁体   English

如何在while循环中循环一个按钮,并在每次迭代中为其赋予不同的ID?

[英]How do I loop one button in a while loop and give it different id's in each iteration?

I need the button id in the table to change however many times the while loop occurs. 我需要表中的按钮ID来更改,但是while循环发生了很多次。 The button works when the loop occurs one time, once it loops more than once then the buttons stop working. 当循环发生一次时,按钮起作用,一旦循环不止一次,则按钮停止工作。 How should I format this php code so the buttons will work after one loop. 我应该如何格式化此php代码,以便按钮在一个循环后正常工作。 Also the button is just a drop down with four functions in it. 同样,该按钮只是一个下拉菜单,其中包含四个功能。

I have tried having a variable id in the divs, dropdown, and button that increments and it still doesn't work. 我试过在div,下拉列表和按钮中增加一个变量id,但它仍然不起作用。 I put the incrementing variable in the Details button to see of it was working. 我将递增变量放在“详细信息”按钮中,以查看它是否正常工作。 After doing research my hypothesis was that since the id is incrementing by one in each loop that means all the button ids will be different and the buttons that are echoed out will function independently of each other but that isn't the and they don't function at all. 经过研究后,我的假设是,由于id在每个循环中递增1,这意味着所有按钮id都将不同,并且被回显的按钮将彼此独立起作用,但这不是,并且它们不会发挥作用。

$c=1;
while($row =  sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ){

$button = <div id='".$c."' class='dropdown'>
<button value='".$c."' id='".$c."' type='button' class='btn btn-primary 
dropdown-toggle' data-toggle='dropdown'> $c Details <span class='caret'> 
</span></button>
<ul value='".$c."' id='".$c."' class='dropdown-menu'>
<li><a href='#' id='action1'><span class ='glyphicon glyphicon-th-list 
glyph-to-left'></span> Children</a></li>
<li><a href='#' id='action2'><span class ='glyphicon glyphicon-tasks glyph- 
 to-left'></span> Pets</a></li>
 <li><a href='#' id='action3'><span class ='glyphicon glyphicon-list-alt 
 glyph-to-left'></span> Parents</a></li>
 <li><a href='#' id='action4'><span class ='glyphicon glyphicon-cloud- 
 download glyph-to-left'></span> Grandparents</a></li>
 </ul>
 </div>
 </div>;

 echo "<tr><td>". $row['Username'] ."</td><td>". $row['asset id'] ." 
 </td><td>" . $row['Firstname'] ."</td><td>" . $row['Lastname'] ."</td> 
 <td>" . $row['asset type'] ."</td><td>". 
 $row['Date']->format('M-d-Y')."</td><td>" . $row['Marital Status']. " 
 </td><td>" . $row['operational status']. "</td><td>". 
 $row['Yearly Income'] ."</td><td>" . $row['Taxes']. " 
 </td><td>". $button. "</td></tr>";

有一个计数器变量,并将其值作为字符串包含在ID的末尾

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM